#include <iostream>
#include <string>
#include <cctype>
#include <cstring>
#include <cstdlib>
using namespace std;
char a[1500000][50];
int compare(const void *a,const void *b)
{
return strcmp((char *)a,(char *)b);
}
int main ()
{
char c;
int i = 0, j = 0, f = 0;
while(1)
{
c = cin.get();
if(c<=0)break;
if(isalpha(c))
{
a[i][j] = tolower(c);
j++;
f = 1;
}
else if(!isalpha(c)&&f)
{
i++;
j = 0;
f = 0;
}
}
qsort(a,i,sizeof(a[0]),compare);
char ch[50];
for(int j = 0; j < i; j++)
{
if(strcmp(a[j],ch))
{
cout<<a[j]<<endl;
strcpy(ch,a[j]);
}
}
return 0;
}
这个题我败在了思路上,算法还算简单,但是思考不全面。例如 a/bc 这样的例子就没想到。
UVA10815-安迪的第一个字典
最新推荐文章于 2022-01-18 16:54:23 发布