1550:simple String Time limit: 1 Sec Memory Limit: + MB
Submit: 249 Solved: 112
[Submit] [Status] [Web Board] Description
Welcome,this is the 3th multiple universities programming Contest, Changsha, Hunan province. In order to let's feel fun, acgege'll give you a simple problem. But was that true? OK, let ' s enjoy it.
There is three strings A, B and C. The length of the string A is 2*n, and the length of the string B and C are same to A. You can take n characters from A and take n characters from B. Can you set them to C?
Input
There is several test cases.
Each test case contains three lines a,b,c. They only contain upper case letter.
0<n<100000
The input would finish with the end of file.
Output
If you can get C, please print "YES". If you cann ' t get C, please print "NO".
Sample Input
Aabbbbccaaccaaaabbbbaaaa
Sample Output
YESNO
HINTTest Instructions:
The title of the topic is to give you two strings of length 2*n, a, B, and then given a 2*n long string c,c string consisting of n strings in A, B, to determine whether a given two string can form C.
Analysis:
By test instructions, we can list 9 scenarios: Judging if a string in C is compliant with test instructions.
Because one of the letters in A, B is up to N to form C, (when a string of a B is greater than n, it can only be taken out of N) in order to satisfy the conditions that make up the C string.
|
A[i]<n |
A[i]=n |
A[i]>n |
B[i]<n |
C[i]<=a+b |
C[i]<=a+b |
C[i]<=n+b |
B[i]=n |
C[i]<=a+b |
C[i]<=a+b |
C[i]<=b+n |
B[i]>n |
C[i]<=a+n |
C[i]<=a+n |
C[i]<=n+n |
The following is the code for AC:
#include <iostream> #include <string.h> #include <algorithm>using namespace Std;int a[26], b[26], c[26 ];bool Flag[26];char Str[200002];int Main () {int i, lenth; while (CIN >> str) {memset (A, 0, sizeof (a)); memset (b, 0, sizeof (b)); memset (c, 0, sizeof (c)); Lenth = strlen (str); for (i=0; i<lenth; i++) {a[str[i]-' a ']++;//counts the number of letters in a string} cin >> str; for (i=0; i<lenth; i++) {b[str[i]-' A ']++;//statistics B The number of letters in the string} cin >> str; for (i=0; i<lenth; i++) {c[str[i]-' A ']++; } memset (flag, true, sizeof (flag)); for (i=0; i<26; i++) {if (A[i] > Lenth/2) {a[i] = LENTH/2;//When a letter in a is &G T N, a maximum of n can be provided, the assignment is n} if (B[i] > Lenth/2) {b[i] = LENTH/2; } if (C[i] <= a[i] + b[i])//when C characterString satisfies yes, marked as false {Flag[i] = false; }} for (i=0; i<26; i++) {if (flag[i] = = True)//c string has a not satisfied, jump out of the loop { Break }} if (i<26) {cout << "NO" << Endl; } else {cout << "YES" << Endl; }} return 0;}
CSU 1550:simple String (String)