View Code of Problem 97

#include <stdio.h>
#include <string.h>
typedef struct node{
    char ch[20];
}node;

int comp(const void* a,const void* b)
{
    node* c = (node*)a;
    node* d = (node*)b;
    return (strcmp(c->ch,d->ch));
}

int main(void)
{
    int n;
    while(scanf("%d",&n) != EOF && n)
    {
        int i,j,index1 = 0,index2 = 0;
        char s[20],s1[20],s2[20],str[1000][20];
        node exe[1000];
        for(i = 0;i < n;i++)
        {
            int k = 0;
            scanf("%s",s);
            if(strlen(s) < 5)
                strcmp(str[index1++],s);
            else
            {
                for(j = strlen(s) - 4;j < strlen(s);j++)
                {
                    s1[k++] = s[j];
                }
                strncpy(s2,s,strlen(s) - 4);
                s2[strlen(s) - 4] = '\0';
                s1[k] = '\0';
                if(strcmp(s1,".exe") == 0)
                {
                    strcpy(exe[index2++].ch,s2);
                }
                else
                {
                    strcpy(str[index1++],s);
                }
            }
        }
        qsort(exe,index2,sizeof(node),comp);
        for(i = 0;i < index2;i++)
        {
            for(j = 0;j < index1;j++)
            {
                if(strcmp(exe[i].ch,str[j]) == 0)
                {
                    printf("%s.exe\n",exe[i].ch);
                    break;
                }
            }
        }
    }
    return 0;
}

Double click to view unformatted code.


Back to problem 97