UVA10252 POJ2629 Common Permutation【字符串排序】
2017-03-17 08:34
399 查看
Common permutation
Description
Given two strings of lowercase letters, a and b, print the longest string x of lowercase letters such that there is a permutation of x that is a subsequence of a and there is a permutation of x that is a subsequence of b.
Input
Input consists of pairs of lines. The first line of a pair contains a and the second contains b. Each string is on a separate line and consists of at most 1,000 lowercase letters.
Output
For each subsequent pair of input lines, output a line containing x. If several x satisfy the criteria above, choose the first one in alphabetical order.
Sample Input
Sample Output
Source
The UofA Local 1999.10.16
问题链接:UVA10252 POJ2629 Common Permutation。
问题描述:
两个小写字母构成的字符串a和b,求各自的置换的最长公共子串,按字母顺序输出。
问题分析:(略)。
程序说明:
字符串类型变量的排序也是可以用函数sort()实现的。
AC的C++语言程序如下:
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 5782 | Accepted: 1749 |
Given two strings of lowercase letters, a and b, print the longest string x of lowercase letters such that there is a permutation of x that is a subsequence of a and there is a permutation of x that is a subsequence of b.
Input
Input consists of pairs of lines. The first line of a pair contains a and the second contains b. Each string is on a separate line and consists of at most 1,000 lowercase letters.
Output
For each subsequent pair of input lines, output a line containing x. If several x satisfy the criteria above, choose the first one in alphabetical order.
Sample Input
pretty women walking down the street
Sample Output
e nw et
Source
The UofA Local 1999.10.16
问题链接:UVA10252 POJ2629 Common Permutation。
问题描述:
两个小写字母构成的字符串a和b,求各自的置换的最长公共子串,按字母顺序输出。
问题分析:(略)。
程序说明:
字符串类型变量的排序也是可以用函数sort()实现的。
AC的C++语言程序如下:
/* UVA10252 POJ2629 Common Permutation */ #include <iostream> #include <algorithm> #include <string> #include <cstring> #include <cstdio> 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<lena && j<lenb; ) { if(a[i] == b[j]) { printf("%c", a[i]); i++, j++; } else if(a[i] > b[j]) j++; else if(a[i] < b[j]) i++; } printf("\n"); } return 0; }
相关文章推荐
- uva 10252 - Common Permutation 字符串水题
- (字符串的处理4.7.14)UVA 10252 Common Permutation(寻找两个字符串中的共同字符&&按字典序输出)
- UVa——110303 Common Permutation(字符串)
- 2018_1_31_Common permutation_字符串基础题
- 字符串 UVa 10252 Common Permutation (公共排列)
- uva 10252 - Common Permutation 字符串水题
- 字符串排序输出函数
- 对汉字字符串按照拼音排序
- acm 试题 字符串排序
- javascript 字符串简单排序
- [python]一行搞定字符串排序
- [python]一行搞定字符串排序
- Hibernate不支持Oracle对字符串排序后的基于rownum的取数方式
- 字符串排序的程序代码 acm试题
- 字符串技巧排序
- 按拼音或者笔画排序你的字符串
- 对字符串数组进行排序,在冒泡法排序中使用compareTo()方法确定排序的顺序。
- 按照字符串排序的Sql写法
- java中文字符串按拼音排序 代码
- STL对字符串排序