题目链接:https://abc082.contest.atcoder.jp/tasks/abc082_b
Time limit : 2sec / Memory limit : 256MB
Score : 200 points
Problem Statement
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s'<t' for the lexicographic order.
Notes
For a string a=a1a2…aN of length N and a string b=b1b2…bM of length M, we say a<b for the lexicographic order if either one of the following two conditions holds true:
- N<M and a1=b1, a2=b2, ..., aN=bN.
- There exists i (1≤i≤N,M) such that a1=b1, a2=b2, ..., ai−1=bi−1 and ai<bi. Here, letters are compared using alphabetical order.
For example, xy
< xya
and atcoder
< atlas
.
Constraints
- The lengths of s and t are between 1 and 100 (inclusive).
- s and t consists of lowercase English letters.
Input
Input is given from Standard Input in the following format:
s
t
Output
If it is possible to satisfy s'<t', print Yes
; if it is not, print No
.
Sample Input 1
yx
axy
Sample Output 1
Yes
We can, for example, rearrange yx
into xy
and axy
into yxa
. Then, xy
< yxa
.
Sample Input 2
ratcode
atlas
Sample Output 2
Yes
We can, for example, rearrange ratcode
into acdeort
and atlas
into tslaa
. Then, acdeort
< tslaa
.
Sample Input 3
cd
abc
Sample Output 3
No
No matter how we rearrange cd
and abc
, we cannot achieve our objective.
Sample Input 4
w
ww
Sample Output 4
Yes
Sample Input 5
zzz
zzz
Sample Output 5
No 补漏洞
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
using namespace std;
char a[];
char b[];
int main()
{
while(scanf("%s%s",&a,&b)!=EOF){
int la=strlen(a);
int lb=strlen(b);
sort(a,a+la);
sort(b,b+lb);
if(a[]<b[lb-]) cout<<"Yes"<<endl;
else if(a[]>b[lb-]) cout<<"No"<<endl;
else{
if(a[]==a[la-]&&b[]==b[lb-]&&a[]==b[]){
if(lb>la) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
continue;
}
int k=;
for(int i=;i<la;i++){
for(int j=;j<lb;j++){
if(b[j]>a[i]){
k++;
break;
}
}
}
if(k==la) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
}
return ;
}