View Code of Problem 22

#include<bits/stdc++.h>
using namespace std;
int main(){
	char a[1010];
	char b[1010];
	while(gets(a)!=NULL){
		gets(b);
		int k = 0;
		char aa[200];
		for(int i = 0;i<strlen(a);i++){
			for(int j = 0;j<strlen(b);j++){
				if(a[i]==b[j]){
					aa[k++] = a[i];
					b[j] = '1';
					break;
				}
			}
		}
		sort(aa,aa+k);
		for(int i = 0;i<k;i++) cout<<aa[i];	 
		cout<<endl;
	} 
	return 0;
}

Double click to view unformatted code.


Back to problem 22