// Common Permutation (公共排列)
// PC/UVa IDs: 110303/10252, Popularity: A, Success rate: average Level: 1
// Verdict: Accepted
// Submission Date: 2011-05-22
// UVa Run Time: 0.044s
//
// 版权所有(C)2011,邱秋。metaphysis # yeah dot net
#include <iostream>
#include <algorithm>
using namespace std;
bool cmp(char a, char b)
{
return a < b;
}
int main(int ac, char *av[])
{
string a;
string b;
while (getline(cin, a), getline(cin, b))
{
// 比较前先按字典排序,保证输出的是字典序。
sort(&a[0], &a[0] + a.length(), cmp);
sort(&b[0], &b[0] + b.length(), cmp);
// 查找共有的字符,不同的忽略。
int i = 0;
int j = 0;
while (i < a.length() && j < b.length())
{
if (a[i] == b[j])
{
cout << a[i];
i++;
j++;
}
else
{
if (a[i] < b[j])
i++;
else
j++;
}
}
cout << endl;
}
return 0;
}
UVa Problem 10252 Common Permutation (公共排列)
最新推荐文章于 2021-08-04 15:15:41 发布