Andy's First Dictionary(uva 10815)
#include <iostream>#include <string>
#include <set>
#include <algorithm>
using namespace std;
int main()
{
set<string> s;
string str[5050];
string str2;
int t = 0;
while(!cin.eof()) //直至按ctrl+z键退出!
{
getline(cin,str[t++]);
}
for(int i = 0; i < t; i++)
transform(str[i].begin(), str[i].end(), str[i].begin(), ::tolower);
for(int i = 0; i < t; i++)
{
str2.clear();bool cnt = false;
for(int j = 0; j < str[i].length(); j++)
{
if(isalpha(str[i][j])){
cnt = true;
str2 += str[i][j];
}
else {
if(cnt){
s.insert(str2);
cnt = false;
str2.clear();
}
}
}
if(cnt){
s.insert(str2);
cnt = false;
str2.clear();
}
}
for(set<string>::iterator it = s.begin(); it != s.end(); it++)
cout << *it << endl;
return 0;
}
//循环输入到EOF
/* string str[5050];
string str2;
int t = 0;
while(!cin.eof()) //直至按ctrl+z键退出!
{
getline(cin,str[t++]);
}*/