acm--string--csu--1550--Simple string

Source: Internet
Author: User


Central South University OJ title address: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1550

1550:simple String Time limit: 1 Sec Memory Limit: + MB
Submit: 471 Solved: 206
[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

================================= 's split line ===============================


Test 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




#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&GT;&GT;STR) {int len=strlen (str);       Initializes an array of memset (A,0,sizeof (A));       memset (b,0,sizeof (B));       memset (c,0,sizeof (C));       Reads the data into A array for (i=0;i<len;i++) {a[str[i]-' a ']++;       } cin>>str;       Reads the data into the B array for (i=0;i<len;i++) {b[str[i]-' A ']++;       } cin>>str;       Reads the data into the C array for (i=0;i<len;i++) {c[str[i]-' A ']++;       } memset (Flag,true,sizeof (flag));          for (i=0;i<26;i++) {if (A[I]&GT;LEN/2) {///when the number of a letter in a is greater than N, only n A[I]=LEN/2 can be taken;          if (B[I]&GT;LEN/2) {//When the number of a letter in B is greater than N, only n B[I]=LEN/2 can be taken;          } if (C[i]<=a[i]+b[i]) {flag[i]=false;    }}//loop judgment is not all false for (i=0;i<26;i++) {if (flag[i]==true) {break;      }} if (i<26) {cout<< "NO" <<endl;       }else{cout<< "YES" <<endl; }} return 0;}



Reference Blog: http://blog.csdn.net/whjkm/article/details/45510167

acm--string--csu--1550--Simple string

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.