View Code of Problem 97

#include <stdio.h>
#include <string.h>
int main(){
  char a[1000][1000];
  char b[1000][1000];
  char str[1000];
  char c[1000];
  int n,i,j,m,k,p;
  while (1){
    scanf("%d",&n);
	k=0;
    if(n!=0){
      for(i=0;i<n;i++)
      scanf("%s",a[i]);
      for(j=0;j<n;j++){
      m=strlen(a[j]);
        if(a[j][m-1]=='e'&&a[j][m-2]=='x'&&a[j][m-3]=='e'&&a[j][m-4]=='.'){
          strcpy(str,a[j]);
          str[m-4]='\0';
          for(p=0;p<n;p++)
            if(strcmp(str,a[p])==0&&p!=j){
              strcpy(b[k++],a[p]);
              break;
            }
          
            
        }
          
      
    }
      if(k>0){
        if(k=1)
          printf("%s",b[0]);
        if(k>1){
      for(i=0;i<k;i++){
        for(j=i+1;j<k;j++){
          if (strcmp(b[i],b[j])>0){
            strcpy(c,b[j]);
            strcpy(b[j],b[i]);
            strcpy(b[i],c);
        }
      }
  }
      }
      }
             for(i=0;i<k;i++)
		      	 puts(b[i]);
  }
	else
       break;
}
  
  
  
  return 0;
}

Double click to view unformatted code.


Back to problem 97