View Code of Problem 22

#include<iostream>
using namespace std;
//注意名字有空格 如果相同字母出现多次也要算 
int main() {
	string a,b;
	while(getline(cin,a)) {
		getline(cin,b);
		int zm[26]={0},zm2[26]={0},zm3[26]={0};
		//统计次数 
		for(int i=0; i<a.length(); i++) zm[a[i]-'a']++;
		for(int i=0; i<b.length(); i++) zm2[b[i]-'a']++;	
		for(int i=0; i<26; i++) {
			if(zm[i]!=0&&zm2[i]!=0) zm3[i]=zm[i]>zm2[i]?zm2[i]:zm[i];
		}	
		for(int i=0; i<26; i++) {
			if(zm3[i]!=0) {
				for(int j=0; j<zm3[i]; j++) cout<<char('a'+i);
			}
		}
		cout<<endl;
	}
}

Double click to view unformatted code.


Back to problem 22