ACM--字符串--CSU--1550-- Simple String
2016-04-24 17:09
316 查看
中南大学OJ题目地址:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1550
256 MB
Submit: 471 Solved: 206
[Submit][Status][Web
Board]
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 ?
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.
=================================傲娇的分割线===============================
题意:
题目的意思是给你两个长度为2*N的字符串,A,B,然后给定一个2*N长的字符串C,C字符串分别由A,B中的N个字符串组成,判断给定的两个字符串能否组成C。
分析:
由题意,我们就可以列出9种情况:判断c中的某个字符串是否符合题意。
因为A,B中的某个字母最多拿出N个去组成C,(当A,B字符串中的某个字母如果大于N个时,也最多只能拿出N个出来)这样才能满足组成C字符串的条件。
参考博客:http://blog.csdn.net/whjkm/article/details/45510167
1550: Simple String
Time Limit: 1 Sec Memory Limit:256 MB
Submit: 471 Solved: 206
[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’s enjoy 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
题意:
题目的意思是给你两个长度为2*N的字符串,A,B,然后给定一个2*N长的字符串C,C字符串分别由A,B中的N个字符串组成,判断给定的两个字符串能否组成C。
分析:
由题意,我们就可以列出9种情况:判断c中的某个字符串是否符合题意。
因为A,B中的某个字母最多拿出N个去组成C,(当A,B字符串中的某个字母如果大于N个时,也最多只能拿出N个出来)这样才能满足组成C字符串的条件。
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 |
#include <iostream> #include <string.h> using namespace std; int A[26],B[26],C[26]; char str[100001]; bool flag[26]; int main(){ int i; while(cin>>str){ int len=strlen(str); //初始化数组 memset(A,0,sizeof(A)); memset(B,0,sizeof(B)); memset(C,0,sizeof(C)); //将数据读入A数组 for(i=0;i<len;i++){ A[str[i]-'A']++; } cin>>str; //将数据读入B数组 for(i=0;i<len;i++){ B[str[i]-'A']++; } cin>>str; //将数据读入C数组 for(i=0;i<len;i++){ C[str[i]-'A']++; } memset(flag,true,sizeof(flag)); for(i=0;i<26;i++){ if(A[i]>len/2){//当A中的某个字母的数量大于N的时候只能取N个 A[i]=len/2; } if(B[i]>len/2){//当B中的某个字母的数量大于N的时候只能取N个 B[i]=len/2; } if(C[i]<=A[i]+B[i]){ flag[i]=false; } } //循环判断是不是全部都是false for(i=0;i<26;i++){ if(flag[i]==true){ break; } } if(i<26){ cout<<"NO"<<endl; }else{ cout<<"YES"<<endl; } } return 0; }
参考博客:http://blog.csdn.net/whjkm/article/details/45510167
相关文章推荐
- hadoop2.4.1伪分布环境搭建
- 正则的使用4
- unity3D 5中如何修改及显示Text的值
- Unity协程介绍以及使用
- IOS 设计模式 享元模式
- hdu 1147(线段相交)
- C++生成希尔伯特矩阵
- KVO实现原理
- JAVA面试题---多态成员变量的特点
- Tricks(四十)—— 神经网络解决与(或)及异或问题
- 慵懒的午后
- 电商秒杀和抢购的限流方案
- Java NIO 系列教程(8):SocketChannel
- 两个不一样的fragment中控件id一样造成的bug
- android仿IOS底部弹对话框
- 输入一个整数数组,判断该数组是不是某二元查找树的后序遍历的结果
- description方法和descriptionWithLocale:方法 解决中文现问题
- PHP函数
- 【BZOJ 2154】Crash的数字表格
- Linux内核分析 期中总结