UVA - 10815 Andy's First Dictionary C++

思路:就……放在set里就好了。

介绍两个函数isalpha判断大小写,tolower把大写改为小写。

代码:

#include<iostream>
#include<set>
#include<string>
#include<cctype>
#include<sstream>
using namespace std;
int main()
{
    set<string> se;
    string s,ans;
    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>>ans)se.insert(ans);
    }
    set<string>::iterator it;
    for(it=se.begin();it!=se.end();it++)
    {
        cout<<*it<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/Zero_979/article/details/81095847