Guest User

Untitled

a guest
Jan 22nd, 2014
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.93 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4.  
  5.  
  6. int compare (const void *a, const void *b){
  7.    
  8.         char **a1=(char**)a;
  9.         char **b1=(char**)b;
  10.         return strcmp(*a1,*b1);
  11.    
  12. }
  13.  
  14.  
  15. int main(){
  16.  
  17.     int n,i,j,occ,stop;
  18.     char* temp;
  19.     char** a;
  20.     char** b;
  21.     char p[101];
  22.     scanf("%d",&n);
  23.     a=(char**)malloc(n*sizeof(char*));
  24.     for(i=0;i<n;i++)
  25.         a[i]=NULL;
  26.     occ=0;
  27.     for(i=0;i<n;i++){
  28.         scanf("%s",p);
  29.         j=0;
  30.         stop=0;
  31.         while(a[j]!=NULL&&!stop){
  32.             if(strcmp(a[j],p)!=0)   j++;
  33.                 else stop=1;
  34.         }
  35.         if(!stop){
  36.             a[j]=(char*)malloc(101*sizeof(char));
  37.             strcpy(a[j],p);
  38.             occ++;
  39.         }
  40.     }
  41.     b=(char**)malloc(occ*sizeof(char*));
  42.     for(i=0;i<occ;i++)
  43.         strcpy(b[i],a[i]);
  44.     qsort(b,occ,sizeof(char*),compare);
  45.     for(i=0;i<occ;i++){
  46.         temp=(char*)malloc(101*sizeof(char));
  47.         strcpy(temp,b[i]);
  48.         j=strlen(temp);
  49.         if(j>1){
  50.             if(temp[j-1]=='o'){
  51.                 if(temp[j-2]=='t')
  52.                     printf("%s",temp);
  53.             }
  54.         }
  55.     }
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment