UVA 10815 (字符串处理)

来源:互联网 发布:剑灵邀请一直网络忙 编辑:程序博客网 时间:2024/05/16 11:25

题目意思:


给你一些文字  包含空格 回车 各种标点

然后你从中找到不同的单词  然后输出就好


思路

 string 排序  然后把不同的扔出来 


坑点 

排序后的第一个点可能是空行 或者乱七八糟的字符什么的  在输出第一个点的时候千万要判断下  

我在这里wa无数次 辛酸~~


#include <iostream>#include <cstring>#include <algorithm>#include <ctype.h>#include <cstdio>using namespace std;string S;struct Node{string s;}str[5000005];bool cmp(const Node &a, const Node &b) {return a.s < b.s;}int main(){    int cnt = 0;while (cin >> S) {        for (int i = 0; i < S.length(); i ++) {            if(isalpha(S[i])) {                str[cnt].s += tolower(S[i]);            } else cnt ++;        }        cnt ++;}if(!cnt)return 0;sort(str , str + cnt , cmp);if(isalpha(str[0].s[0]))cout << str[0].s << endl;for (int i = 1; i < cnt; i ++) {        if(str[i].s != str[i - 1].s )        cout << str[i].s << endl;}}/*Adventures inTwo blondes were going to Disneyland when they came to a fork in the road. The sign read: "Disneyland Left."Soooooo they went home.*/