PC/UVa 110303/10252 Common Permutation
来源:互联网 发布:js登录界面源代码 编辑:程序博客网 时间:2024/04/27 20:40
给出两个字符串 a和b 输出满足如下条件的最长串 x : x的某两个排序分别是a 和b的(不必连续)的子序列
首先注意 最长的串,不必连续的,我第一反应就是动态规划,再仔细一看,x 的某两个排序 也就是说,x是由a和b所含有的相同的字符组成的,但是x要从小到大输出
有一点我恨不能理解,他明明说输入的每一行是由小写字母组成的字符串,但是这些字符串中居然含有空格,搞得我很郁闷,晕!
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
#define maxnum 1005
char str1[maxnum],str2[maxnum];
int l1,l2;
bool cmp(char a,char b)
{
return a<b;
}
int main()
{
int i,j;
while(cin.getline(str1,maxnum),cin.getline(str2,maxnum))
{
l1=strlen(str1);
l2=strlen(str2);
sort(&str1[0],&str1[0]+l1,cmp);
sort(&str2[0],&str2[0]+l2,cmp);
i=0;
j=0;
int flag=0;
while(i<l1&&j<l2)
{
if(str1[i]==str2[j])
{
cout<<str1[i];
i++;
j++;
}
else if(str1[i]>str2[j])
j++;
else i++;
}
printf("\n");
}
return 0;
}
cin.getline(arryName,strlen(arryName));//可以读空格,但是cin没办法读空格
- PC/UVa 110303/10252 Common Permutation
- uva-10252-Common Permutation
- UVa 10252 Common Permutation
- uva 10252Common Permutation
- Uva 10252 - Common Permutation
- UVa 10252 - Common Permutation
- UVA--10252 Common Permutation
- Uva OJ 10252 - Common Permutation
- 6 UVA 10252 Common Permutation
- UVa Problem Solution: 10252 - Common Permutation
- uva 10252 - Common Permutation 字符串水题
- Uva 10252 Common Permutation 公共排序
- UVa 10252 Common Permutation (water ver.)
- UVa Problem 10252 Common Permutation (公共排列)
- 字符串 UVa 10252 Common Permutation (公共排列)
- 110303 Common Permutation
- 10252 - Common Permutation
- Common Permutation
- java网络中的UDP/TCP协议
- find 详解
- C++内存管理
- sh:Dos ->unix
- 用信号量保护数据
- PC/UVa 110303/10252 Common Permutation
- Stream 和 byte[] 之间的转换
- postfix 错误汇总
- MessageBox.Show方法出现“容量超出了最大容量。参数名: capacity”错误!
- 网络基础知识
- 最小割集Stoer-Wagner算法,网络最大流问题
- 专注于操作系统9之保护模式基础知识b
- 上传图片前预览
- 使用dinput 出现error LNK2001: 无法解析的外部符号