View Code of Problem 22

#include<bits/stdc++.h>
using namespace std;

int main (){
	char s1[1010];
	while(gets(s1)){
        char s2[1010], str[1010];
        gets(s2);
		int cnt = 0;
		for(int i = 0;i < strlen(s1);i++){
			for(int j = 0;j < strlen(s2);j++){
				if(s1[i]==s2[j]){
					str[cnt++] = s1[i];
					s2[j] = '#';
					break;
				}
			}
		}
		str[cnt] = 0;
		sort(str, str+cnt);
		puts(str);
        memset(s1, 0, sizeof(s1));
        memset(s2, 0, sizeof(s2));
        memset(str, 0, sizeof(str));
	}

	return 0;
}

Double click to view unformatted code.


Back to problem 22