Skip to content

Instantly share code, notes, and snippets.

@KT-Yeh
Created December 29, 2013 07:54
Show Gist options
  • Save KT-Yeh/8168434 to your computer and use it in GitHub Desktop.
Save KT-Yeh/8168434 to your computer and use it in GitHub Desktop.
#include <cstdio>
#include <algorithm>
#include <string.h>
using namespace std;
struct dictionary_type
{
char word[250];
}dic[100000];
bool cmp(dictionary_type a,dictionary_type b)
{
return strcmp(a.word,b.word)<0;
}
int main()
{
char temp[250];
int i,j,dic_i=0;
while(scanf("%s",temp)!=EOF){
for(i=0,j=0;temp[i];i++){
if(temp[i]>='A' && temp[i]<='Z')
dic[dic_i].word[j++]=temp[i]-'A'+'a'; //換成小寫
else if(temp[i]>='a' && temp[i]<='z')
dic[dic_i].word[j++]=temp[i];
else if(j) {dic_i++; j=0;} // apple'is 要被分成兩個字apple跟is
}
if(j) dic_i++; //if(j) 避免words'的情況
}
sort(dic,dic+dic_i,cmp);
for(i=0;i<dic_i;){
printf("%s",dic[i].word);
for(j=i+1; j<dic_i ;j++)
if(strcmp(dic[i].word,dic[j].word)) break;
i=j;
printf("\n");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment