View Code of Problem 97

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

Double click to view unformatted code.


Back to problem 97