#include <stdio.h> #include <string.h> #include <math.h> #include <ctype.h> int main(){ char name1[1001], name2[1001], repeat[1001]; int k; while(gets(name1)) { gets(name2); k = 0; for(int i = 0, l1 = strlen(name1); i < l1; i ++) { for(int j = 0, l2 = strlen(name2); j < l2; j ++) { if(name1[i] == name2[j]) { repeat[k ++] = name1[i]; name2[j] = '*'; break; } } } repeat[k] = '\0'; char c; for(int i = 0; i < k; i ++) { for(int j = i + 1; j < k; j ++) { if(repeat[i] > repeat[j]){ c = repeat[i]; repeat[i] = repeat[j]; repeat[j] = c; } } } puts(repeat); } return 0; } |
Double click to view unformatted code.