View Code of Problem 97

#include<string.h>
#include<stdio.h>
#include<math.h>
int main()
{
    int n,i,j;
    while(scanf("%d",&n) != EOF)
    {
        if(!n)
            break;
        char s[n][20];
        char s1[n][20];
        char t[20];
        int k=0;
        for(i=0;i<n;i++)
            scanf("%s",s[i]);
        for(i=0;i<n;i++){
            int l=strlen(s[i]);
            if(s[i][l-1]=='e'&&s[i][l-2]=='x'&&s[i][l-3]=='e'&&s[i][l-4]=='.')
            {
                strcpy(t,s[i]);
                t[l-4]= '\0';
                for(j=0;j<n;j++){
                    if(strcmp(t,s[j])==0){
                        strcpy(s1[k++],s[i]);
                        break;
                    }
                }
            }
        }
        for(i=0;i<k-1;i++){
            for(j=k-1;j>i;j--){
                if(strcmp(s1[j-1],s1[j])>0)
                {
                    strcpy(t,s1[j-1]);
                    strcpy(s1[j-1],s1[j]);
                    strcpy(s1[j],t);
                }
            }
        }
        for(i=0;i<k;i++){
            puts(s1[i]);
        }
    }
}

Double click to view unformatted code.


Back to problem 97