POJ 2629:Common permutation
2016-02-01 12:29
190 查看
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
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 5510 | Accepted: 1681 |
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
你 离 开 了 , 我 的 世 界 里 只 剩 下 雨 。 。 。
#include <iostream> #include <string> #include <algorithm> using namespace std; int main() { int i, j, lena, lenb; string a, b, ans; while (getline(cin, a), getline(cin, b)) { lena = a.length(); lenb = b.length(); ans.clear(); for (i = 0; i < lena; i++) for (j = 0; j < lenb; j++) if (a[i] == b[j]) { ans.push_back(a[i]); b[j] = '-1'; break; } sort(ans.begin(), ans.end()); cout << ans << endl; } }
相关文章推荐
- 超级台阶
- JSP的九大内置对象和四个作用域
- Codeforces Round #341 (Div. 2) B. Wet Shark and Bishops (正副对角线规律)
- hadoop 启动错误解决办法Retrying connect to server: master/192.168.1.240:9000. Already tried 0 time(s)
- Asp.Net 网站一键部署技术(上)
- hdu 3342 Legal or Not(拓扑排序)
- 用外部物理路由器时使用Neutron dhcp-agent提供的metadata服务(by quqi99)
- PAT1027
- windows和linux中搭建python集成开发环境IDE——如何设置多个python环境
- 《静静的dojo》 总体教程介绍
- c++初学
- Putty 使用密钥远程登录到linux
- Nodejs,我竟无言以对
- Linux 双网卡双网段,基于源IP的策略路由。
- Codeforces Round #341 (Div. 2)-C. Wet Shark and Flowers(区间概率)
- Codeforces Round #341 (Div. 2) A. Wet Shark and Odd and Even (水)
- 用mimikatz来获取win7的密码
- 机器学习笔记(二)矩估计,极大似然估计
- 算法7-7:有向图简单介绍
- C#远程获取图片文件流的方法