UVA 10815

来源:互联网 发布:linux源码下载 编辑:程序博客网 时间:2024/06/16 14:06

题目大意:输入一些句子,将其中的单词存入字典,用EOF跳出循环,最后将所有单词按字典序输出。

解题思路:将单词分割开的不一定是空格,可能是其他非字母字符。输入一行,然后读单词存入set。最后用迭代器输出。

ac代码:

#include <iostream>#include <set>#include <cstring>using namespace std;set <string>se;set <string>::iterator it;int len;char a[5005], b[5005];int main(){while (scanf("%s", a)!=EOF){len = strlen(a);for (int i=0; i<len; i++){memset(b, 0, sizeof(b));for (int j=0; isalpha(a[i]) && i<len; j++,i++){if (a[i] <= 'Z')a[i] = a[i] - 'A' + 'a';b[j] = a[i];}if (strlen(b))se.insert(b);}}for (it=se.begin(); it!=se.end(); it++)cout << *it << endl;se.clear();return 0;}
原创粉丝点击