uva10815 Andy's First Dictionary(字符串的简单处理)

来源:互联网 发布:老人海边摸蛤 知乎 编辑:程序博客网 时间:2024/06/06 04:16

题目戳这里

题意:
按字典序输出文字段落中出现过的所有单词,出现多次记为一次。

思路:
1.大写换小写。
2.过滤字母以外字符,生成多个单词,将单词插入到set容器中。
3.使用set容器按字典序自动生成所需答案。

ac代码:

/**Author : Flint_x *Created Time : 2015-04-04 17:02:48 *File name : uva10815.cpp */#include<iostream>#include<sstream>#include<fstream>#include<vector>#include<list>#include<deque>#include<queue>#include<stack>#include<map>#include<set>#include<bitset>#include<algorithm>#include<cstdio>#include<cstdlib>#include<cstring>#include<cctype>#include<cmath>#include<ctime>#include<iomanip>using namespace std;const double eps(1e-8);typedef long long lint;set<string>dic;int main(){    //freopen("input.txt","r",stdin);    //freopen("output.txt","w",stdout);    char c;    while(c != EOF){        string word = "";        while(1){            c = getchar();            if((c >= 'A' && c <= 'Z')) c += 32;//          cout << c << endl;            if((c >= 'a' && c <= 'z') ){                word += c;            }            else break;        }        dic.insert(word);    }    dic.erase(dic.begin());    set<string>::iterator it;    for(it = dic.begin();it != dic.end();it ++){        cout << *it << endl;    }    return 0;}
0 0
原创粉丝点击