#include<bits/stdc++.h> using namespace std; void sortfile(char sort[1000][17],int m){ int flag; char tmp[17]; for(int i = m-1;i >= 0; i--){ flag = 0; for(int j = 0; j < i; j++){ if(strcmp(sort[j],sort[j+1])>0){ strcpy(tmp,sort[j]); strcpy(sort[j],sort[j+1]); strcpy(sort[j+1],tmp); flag = 1; } } if(flag == 0) break; } } void print(char sort[1000][17],int m){ for(int i = 0; i < m; i++){ cout<<sort[i]<<endl; } } int main(){ int n; while(cin>>n){ if(n==0) break; char file[1000][17],tmp[17],sort[1000][17]; int m = 0; for(int i = 0 ; i < n; i++){ cin>>file[i]; } for(int i = 0; i < n; i++){ int l = strlen(file[i]); if(file[i][l-1]=='e'&&file[i][l-2]=='x'&&file[i][l-3]=='e'&&file[i][l-4]=='.'){ strcpy(tmp,file[i]); tmp[l-4]='\0'; for(int j = 0; j < n; j++){ if(strcmp(tmp,file[j])==0){ strcpy(sort[m++],file[i]); break; } } } } sortfile(sort,m); print(sort,m); } } |
Double click to view unformatted code.