View Code of Problem 97

#include<stdio.h>
#include<string.h>

int main()
{
  int n,len,i,j;
  while(scanf("%d",&n)!=EOF&&n!=0)
  {
    char a[n][100];
    char b[n][100];
    char temp[100];
    int k=0;
    for(i=0;i<n;i++)
      scanf("%s",a[i]);
    for(i=0;i<n;i++)
    {
      len=strlen(a[i]);
      if(a[i][len-1]=='e'&&a[i][len-2]=='x'&&a[i][len-3]=='e'&&a[i][len-4]=='.')
      {
        strcpy(temp,a[i]);
        temp[len-4]='\0'; //断尾
        for(j=0;j<n;j++)      
        {
		  if(strcmp(temp,a[j])==0)
          {
            strcpy(b[k],a[i]);
			k++;
            break;
          }  
		}
      }
    }
    for(i=0;i<k-1;i++)
      for(j=0;j<k-i-1;j++)
        if(strcmp(b[j],b[j+1])>0)
        {
          strcpy(temp,b[j]);
          strcpy(b[j],b[j+1]);
          strcpy(b[j+1],temp);
        }
    for(i=0;i<k;i++)
      printf("%s\n",b[i]);
  }
  return 0;

}

Double click to view unformatted code.


Back to problem 97