#include <stdio.h> #include <string.h> #define max 1000 int main(){ char a[max],b[max],c[max]; int k; char temp; while(gets(a)!=NULL){ gets(b); k=0; for(int i=0;i<strlen(a);i++){ for(int j=0;j<strlen(b);j++){//把ab中都有的字母放到数组C中 if(a[i]==b[j]){ c[k++]=a[i]; b[j]='#'; break; } } } //现在对C数组中的字符进行排序 for(int i=0;i<k;i++){ for(int j=i+1;j<k;j++){ if(c[j]<c[i]){ temp=c[j]; c[j]=c[i]; c[i]=temp; } } } c[k]='\0'; puts(c); } return 0; } |
Double click to view unformatted code.