题意:读入一串字符串,输出按字典序,从小到大不重复输出所有单词,恰好满足set的特点,第一次用set,结果自己测试对,不过一直WA,求路过的大神指点..
/********************** * author:crazy_石头 * Pro:UVA 10815 * algorithm: set * Judge Status:wrong Answer * Time:ms * Memory:K ***********************/ #include <iostream> #include <cstring> #include <cstdlib> #include <cstdio> #include <set> #include <ctype.h> #include <algorithm> using namespace std; #define rep(i,n) for(int i=0;i<=(n);i++) const int maxn=500+5; set<string> myset; set<string>::iterator st; char text[maxn]; char tarjet[maxn]; inline void transform() { int len=strlen(tarjet); rep(i,len) { if(isupper(tarjet[i])) tarjet[i]+=32; } }//大写转化为小写; int main() { int len,i,cnt; myset.clear(); while(gets(text)) { cnt=0; len=strlen(text); text[len]='\0'; text[len+1]='\0';//读入文章; rep(i,len) { if(isalpha(text[i])) { tarjet[cnt++]=text[i]; } else { tarjet[cnt]='\0'; cnt=0;//准备重新读取字符; transform(); string ss; ss=tarjet; myset.insert(ss); } } } for(st=myset.begin();st!=myset.end();st++) { cout<<*st<<endl; } return 0; } |
* This source code was highlighted by YcdoiT. ( style: Moria )