View Code of Problem 22

#include<iostream>
#include<cstring>
#include<algorithm>

using namespace std;

int main(void){
    char str1[1005];
    char str2[1005],str[1005];
    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;
        while(m<strlen(str1)&&n<strlen(str2)){
            if(str1[m]==str2[n]){
                str[t++]=str1[m];
                m++;
                n++;
            }else if(str1[m]>str2[n]){
                n++;
            }else{
                m++;
            }
        }
        for(int i=0;i<t;i++){
            printf("%c",str[i]);
        }
        printf("\n");
    }
}

Double click to view unformatted code.


Back to problem 22