AtCoder Beginner Contest 082 B - Two Anagrams

题目链接: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≤iN,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

Copy
yx
axy

Sample Output 1

Copy
Yes

We can, for example, rearrange yx into xy and axy into yxa. Then, xy < yxa.


Sample Input 2

Copy
ratcode
atlas

Sample Output 2

Copy
Yes

We can, for example, rearrange ratcode into acdeort and atlas into tslaa. Then, acdeort < tslaa.


Sample Input 3

Copy
cd
abc

Sample Output 3

Copy
No

No matter how we rearrange cd and abc, we cannot achieve our objective.


Sample Input 4

Copy
w
ww

Sample Output 4

Copy
Yes

Sample Input 5

Copy
zzz
zzz

Sample Output 5

Copy
No

补漏洞
 1 #include 
 2 #include 
 3 #include 
 4 #include 
 5 #include <string>
 6 #include 
 7 #include 
 8 #include 
 9 using namespace std;
10 char a[101];
11 char b[101];
12 int main()
13 {
14     while(scanf("%s%s",&a,&b)!=EOF){
15         int la=strlen(a);
16         int lb=strlen(b);
17         sort(a,a+la);
18         sort(b,b+lb);
19         if(a[0]1]) cout<<"Yes"<<endl;
20         else if(a[0]>b[lb-1]) cout<<"No"<<endl;
21         else{
22             if(a[0]==a[la-1]&&b[0]==b[lb-1]&&a[0]==b[0]){
23                 if(lb>la) cout<<"Yes"<<endl;
24                 else cout<<"No"<<endl;
25                 continue;
26             }
27             int k=0;
28             for(int i=0;i){
29                 for(int j=0;j){
30                     if(b[j]>a[i]){
31                         k++;
32                         break;
33                     }
34                 }
35             }
36             if(k==la) cout<<"Yes"<<endl;
37             else cout<<"No"<<endl;
38         }
39     }
40     return 0;
41 }

 

转载于:https://www.cnblogs.com/shixinzei/p/8075879.html

你可能感兴趣的:(AtCoder Beginner Contest 082 B - Two Anagrams)