View Code of Problem 22

#include <iostream>
#include <string.h>
#include <math.h>
#include<algorithm>
#include <stack>
using namespace std;
 //好烦啊,题目每次都说的不清不楚的,真的猜测题目意思都浪费好久
 
int main()
{
	char name1[1000], name2[1000];
	while (gets(name1))
	{
		gets(name2);
		char res[1000];
		int num = 0;
		for (int i = 0; i < strlen(name1); i++) {
			for (int j = 0; j < strlen(name2); j++) {
				if (name1[i] == name2[j]) {
					res[num++] = name1[i];
					name2[j] = ' ';
					break;
				}
			}
		}
		sort(res, res + num);
		for (int i = 0; i < num; i++) {
			cout << res[i];
		}
		cout << endl;
	}
    return 0;
}

Double click to view unformatted code.


Back to problem 22