Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 5782 | Accepted: 1749 |
Description
Input
Output
Sample Input
pretty women walking down the street
Sample Output
e nw et
Source
问题链接:UVA10252 POJ2629 Common Permutation。
问题描述:
两个小写字母构成的字符串a和b,求各自的置换的最长公共子串,按字母顺序输出。
问题分析:(略)。
程序说明:
字符串类型变量的排序也是可以用函数sort()实现的。
AC的C++语言程序如下:
/* UVA10252 POJ2629 Common Permutation */
#include
#include
#include
#include
#include
using namespace std;
int main()
{
string a, b;
int lena, lenb;
while(getline(cin, a) && getline(cin, b)) {
// 计算字符串长度
lena = a.size();
lenb = b.size();
// 字符串排序
sort(a.begin(), a.end());
sort(b.begin(), b.end());
// 匹配求公共子串,输出结果
for(int i=0, j=0; i b[j])
j++;
else if(a[i] < b[j])
i++;
}
printf("\n");
}
return 0;
}