View Code of Problem 22

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main (){
	char s1[1010], s2[1010];
	while(gets(s1)){
		gets(s2);
		char s[1010];
		int cnt = 0;
		sort(s1, s1+strlen(s1));
		sort(s2, s2+strlen(s2));
		for(int i = 0;i < strlen(s1);i++){
			for(int j = 0;j < strlen(s2);j++){
				if(s1[i]==s2[j]){
					s[cnt++] = s1[i];
					s2[j] = '#';
					break;
				}
			}
		}
		s[cnt] = '\0';
		printf("%s\n", s);
	}

	return 0;
}

Double click to view unformatted code.


Back to problem 22