#include<iostream> #include<cstring> #include<algorithm> using namespace std; int main(void){ char str1[1000]; char str2[1000],str[1000]; while(scanf("%s",str1)!=EOF){ getchar(); scanf("%s",str2); sort(str1,str1+strlen(str1)); sort(str2,str2+strlen(str2)); int m=0,n=0,t=0,i; while(m<strlen(str1)&&n<strlen(str2)){ if(str1[m]==str2[n]){ for(i=0;i<t;i++){ if(str1[m]==str[i]){ break; } } if(i==t){ str[t++]=str1[m]; } m++; n++; }else if(str1[m]>str2[n]){ n++; }else{ m++; } } for(i=0;i<t;i++){ printf("%c",str[i]); } printf("\n"); } } |
Double click to view unformatted code.