湖南多校对抗赛3.28 D Simple String
2015-04-05 16:23
369 查看
<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">Problem D: Simple String</span>
Time Limit: 1 Sec Memory Limit: 256 MBSubmit: 74 Solved: 35
[Submit][Status][Web
Board]
Description
Welcome,this is the 2015 3th Multiple Universities Programming Contest ,Changsha ,Hunan Province. In order to let you feel fun, ACgege will give you a simple problem. But is that true? OK, let’senjoy it.
There are three strings A , B and C. The length of the string A is 2*N, and the length of the string B and C is same to A. You can take N characters from A and take N characters from B. Can you set them to C ?
Input
There are several test cases.Each test case contains three lines A,B,C. They only contain upper case letter.
0<N<100000
The input will finish with the end of file.
Output
For each the case, if you can get C, please print “YES”. If you cann’t get C, please print “NO”.Sample Input
AABB BBCC AACC AAAA BBBB AAAA
Sample Output
YES NO
题意:有A,B,C三串字符串,取A,B串的各一半,问能不能组成C;
思路:分别记录A,B,C里面每个元素出现的个数,如果a[i] + b[i] < c[i],那么就直接输出NO;
用min_a记录a最少要拿出几个字母,用max_a记录a最多要拿出几个字母,如果len/2在min_a和max_a之间,就输出YES,否则输出NO。代码如下:
#include<cstdio> #include<cstring> const int maxn=100005; char A[maxn], B[maxn], C[maxn]; int a[maxn], b[maxn], c[maxn]; int main() { while(scanf("%s%s%s", &A, &B, &C)!=EOF) { for(int i=0; i<26; i++) { a[i]=0, b[i]=0, c[i]=0; } int len=strlen(A); for(int i=0; i<len; i++) { a[A[i]-'A']++; } for(int i=0; i<len; i++) { b[B[i]-'A']++; } for(int i=0; i<len; i++) { c[C[i]-'A']++; } int min_a=0, max_a=0; int flag=0; for(int i=0; i<26; i++) { if(a[i]+b[i]<c[i]) { flag=1; printf("NO\n"); break; } else { if(c[i]>b[i]) { min_a+=c[i]-b[i]; } if(a[i]>c[i]) { max_a+=c[i]; } else max_a+=a[i]; } } if(!flag) { int mid=len/2; if(mid>=min_a && mid<=max_a) { printf("YES\n"); } else { printf("NO\n"); } } } return 0; }
相关文章推荐
- 湖南多校对抗赛3.28 J - Jerry's trouble
- 湖南多校对抗赛(D-D)
- 湖南多校对抗赛(2014.03.16) C.Pings
- 湖南多校对抗赛(J - J)
- 湖南多校对抗赛(2014.03.16) 比赛总结贴
- 湖南多校对抗赛(2015.05.24)部分解题报告(CSU1628-1638)
- 第十二场湖南多校对抗赛总结
- 湖南多校对抗赛(2014.03.23)JAG Practice Contest 2013
- 湖南多校对抗赛---Rectangle(01背包)
- Heaps(Contest2080 - 湖南多校对抗赛(2015.05.10)(国防科大学校赛决赛-Semilive)+scu1616)
- 湖南多校对抗赛(2015.4.6) E
- 湖南多校对抗赛---Good subsequence
- Contest2075 - 湖南多校对抗赛(2015.04.26)-C Catalan Square(csu1576)
- 湖南多校对抗赛(2015.4.6)C
- 湖南多校对抗赛(csu 1560)
- 湖南多校对抗赛---Jerry's trouble
- 湖南多校对抗赛(2015.03.28) A Rectangle
- Aquarium Tank(csu1634+几何+二分)Contest2087 - 湖南多校对抗赛(2015.05.24)-G
- 湖南多校对抗赛(2015.03.28)
- 湖南多校对抗赛(2015.03.28) B Design road