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