View Code of Problem 97

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

Double click to view unformatted code.


Back to problem 97