View Code of Problem 22

#include<bits/stdc++.h>
using namespace std;
int main(){
	char a[1005],b[1005];
	while(scanf("%s%s",a,b)!=EOF){
		int aa[30] = { },bb[30] = { };
		for(int i = 0;i<strlen(a);i++){
			aa[a[i]-'a'+1] = 1;
		}
		for(int i = 0;i<strlen(b);i++){
			bb[b[i]-'a'+1] = 1;
		}
		for(int i = 1;i<27;i++){
			if(aa[i] == bb[i]  && aa[i]!=0){
				cout<<(char)(i+'a'-1);
			}
		}
		cout<<endl; 
	}
	
	return 0;
}

Double click to view unformatted code.


Back to problem 22