UVa 10252 Common Permutation (water ver.)
2013-11-09 16:04
411 查看
10252-CommonPermutation
Timelimit:3.000secondsGiventwostringsoflowercaseletters,
aandb,printthelongeststring
xoflowercaseletterssuchthatthereisapermutationof
xthatisasubsequenceofaandthereisapermutationof
xthatisasubsequenceofb.
Input
Inputfilecontainsseverallinesofinput.Consecutivetwolinesmakeasetofinput.Thatmeansintheinputfileline
1and2isasetofinput,line3and
4isasetofinputandsoon.Thefirstlineofapaircontains
aandthesecondcontainsb.Eachstringisonaseparatelineandconsistsofatmost
1000lowercaseletters.
Output
Foreachsetofinput,outputalinecontaining
x.Ifseveralxsatisfythecriteriaabove,choosethefirstoneinalphabeticalorder.
SampleInput:
pretty
women
walking
down
the
street
SampleOutput:
e
nw
et
水。
完整代码:
#include<bits/stdc++.h>
usingnamespacestd;
chara[1005],b[1005],ans[1005];
boolvis[1005];
voidsolve(char*a,char*b)
{
intlena=strlen(a),lenb=strlen(b),i,j,c=0;
memset(vis,0,sizeof(vis));
for(i=0;i<lena;++i)
for(j=0;j<lenb;++j)
{
if(!vis[j]&&a[i]==b[j])
{
ans[c++]=a[i];
vis[j]=true;
break;
}
}
ans[c]=0;
sort(ans,ans+c);
puts(ans);
}
intmain()
{
while(gets(a))
{
gets(b);
if(strlen(a)<strlen(b))solve(a,b);
elsesolve(b,a);
}
return0;
}
相关文章推荐
- uva 10252Common Permutation
- UVa10252:Common Permutation
- (字符串的处理4.7.14)UVA 10252 Common Permutation(寻找两个字符串中的共同字符&&按字典序输出)
- Uva 10252 - Common Permutation
- UVa 10252 - Common Permutation
- uva-10252-Common Permutation
- uva 10252 - Common Permutation 字符串水题
- uva 10252 - Common Permutation 字符串水题
- UVa Problem Solution: 10252 - Common Permutation
- 字符串 UVa 10252 Common Permutation (公共排列)
- UVa Problem 10252 Common Permutation (公共排列)
- UVA--10252 Common Permutation
- UVa 12289 One-Two-Three (water ver.)
- UVa 102 Ecological Bin Packing (water ver.)
- UVa 79 ClockHands (water ver.)
- UVa 11723 Numbering Roads (water ver.)
- UVa 10008 What's Cryptanalysis? (water ver.)
- UVa 11875 Brick Game (water ver.)
- UVa 10656 Maximum Sum (II) (water ver.)
- UVa 11150 Cola (water ver.)