#include<stdio.h> #include<string.h> int main(){ char a[100],b[100],same[100],temp; int i,j,len1,len2,k; while(gets(a) != NULL) { gets(b); k=0; len1 = strlen(a); len2 = strlen(b); for(i=0; i < len1; i++ ) { for(j=0; j < len2; j++) { if(a[i] == b[j]) { same[k++] = b[j]; break; } same[k] = '\0'; } } for(i=0; i < k; i++) { for(j=0; j < k; j++) { if(same[i] > same[j]) { temp = same[i]; same[i] = same[j]; same[j] = temp; } } } for(i=0; i < k; i++) printf("%c",same[i]); printf("\n"); } return 0; } |
Double click to view unformatted code.