fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. typedef struct{
  6. int x;
  7. char str[51];
  8. }Word;
  9. int compare(const void *a,const void *b){
  10. Word *w1=(Word *)a;
  11. Word *w2=(Word *)b;
  12. if (w1->x!=w2->x){
  13. return w1->x-w2->x;
  14. }
  15. return strcmp(w1->str, w2->str);
  16. }
  17. int main(){
  18. int n; scanf("%d",&n);
  19. Word w[n];
  20. for (int i=0;i<n;i++){
  21. gets(w[i].str);
  22. w[i].x=strlen(w[i].str);
  23. }
  24. qsort(w,n,sizeof(Word),compare);
  25. for (int i=0;i<n;i++){
  26. char tmp[51]="";
  27. if (strcmp(tmp,w[i].str)==0) continue;
  28. printf("%s\n",w[i].str);
  29. strcpy(tmp,w[i].str);
  30. }
  31.  
  32.  
  33. }
Success #stdin #stdout 0s 5288KB
stdin
13
but
i
wont
hesitate
no
more
no
more
it
cannot
wait
im
yours
stdout
i
im
it
no
no
but
more
more
wait
wont
yours
cannot
hesitate