View Code of Problem 22

// ConsoleApplication1.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;
int main()
{
	string s1;
	string s2;
	while (cin >> s1 >> s2) {
		int a1[26] = {0};
		int a2[26] = { 0 };
		for (int i = 0; i < s1.length(); i++) {
			a1[s1[i] - 'a']++;
		}
		for (int i = 0; i < s2.length(); i++) {
			a2[s2[i] - 'a']++;
		}
		for (int i = 0; i < 26; i++) {
			if (a1[i]!=0&&a2[i]!=0) {
				int m = min(a1[i], a2[i]);
				while (m--) {
					cout <<(char) (i + 'a');
				}
			}
		}
		cout << endl;
	}
}

// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
// 调试程序: F5 或调试 >“开始调试”菜单

// 入门使用技巧: 
//   1. 使用解决方案资源管理器窗口添加/管理文件
//   2. 使用团队资源管理器窗口连接到源代码管理
//   3. 使用输出窗口查看生成输出和其他消息
//   4. 使用错误列表窗口查看错误
//   5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目
//   6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件

Double click to view unformatted code.


Back to problem 22