UVA_10815 Andy's First Dictionary ( set 的应用 )

题解

水 ... 

代码


法一 

#include <bits/stdc++.h> 
using namespace std ; 
#define rg register 
typedef long long ll ; 




int main ( ) { //freopen( "F:\\in\\set.txt" , "r" , stdin ) ; 

string s , t ; 
set<string> st ; 
st.clear() ; 
    while ( cin >> s ) { 

        t = "" ; 

        rg int len = s.size() ; 
        for ( rg int i = 0; i < len ; ++i ) { 
            if ( isalpha( s[i] ) ) 
                t += tolower( s[i] ) ; 
            else { 
                st.insert( t ) ; 
                t = "" ; 
            }
        }
        st.insert( t ) ; 


    }
        for ( auto it = st.begin() ; it != st.end() ; ++it ) {
            if ( *it != "" ) cout << *it << endl ; 
        }
            
    


    return 0 ; 
} 

法二 

#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <sstream>
using namespace std;

int main()
{
    string s, buf;
    set<string>a;
    while(cin>>s)
    {
        for(int i=0;i<s.length();i++)
        {
            if(isalpha(s[i]))
                s[i] = tolower(s[i]);
            else
                s[i] = ' ';
        }
        stringstream ss(s);
        while(ss >> buf)
        {
            a.insert(buf);
        }

    }
        for(set<string>::iterator it= a.begin();it!=a.end();it++)
        {
            cout<<*it<<endl;
        }
    return 0;
}


题目

在这里插入图片描述

Sample Input
样例输入①
a a a a a a a a, a a a a a a.
a a a a b a a a. a? a!!!
样例输入②
Adventures in Disneyland
Two blondes were going to Disneyland when they came to a fork in the
road. The sign read: “Disneyland Left.”
So they went home.
Sample Output
样例输出①
a
b
样例输出②
a
adventures
blondes
came
disneyland
fork
going
home
in
left
read
road
sign
so
the
they
to
two
went
were
when
Hint
输入可能包含标点符号,但标点符号显然不能算作单词的一部分。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值