hihocoder--Microsoft online Written test T1

Source: Internet
Author: User

Disclaimer: I do not know whether the confidentiality agreement will be involved, just a simple record of their own code.

Enter a string, and X y z three integers

Place the string characters in the box one by one, the current number of n characters is inferior to x y Z, the first n characters disappear, and the remaining characters are placed in the box.

Find out the maximum number of characters the box misses.

(original title is different color of the ball into the box)

Eg: input ("Rrybrbrybry", 4,1,2), output 7

Ideas

Design three functions:

The absolute value of the difference of 1.3 numbers is equal to the given 3 numbers--bool isvanish (int x, int y, int z, int A, int b, int c)

2. String The first few characters can disappear--int isvanish (string s, int x, int y, int z)

3. The maximum number of characters to put in the box

"My Code"

(incomplete, and finally have to add a condom, slightly)

BOOLIsvanish (intXintYintZintAintBintc) {    intAa=abs (A-b); intBb=abs (b-c); intCc=abs (A-c); if(aa==x) {        if((bb==y&&cc==z) | | (bb==z&&cc==y))return true; }    if(aa==y) {        if((bb==x&&cc==z) | | (bb==z&&cc==x))return true; }    if(aa==z) {        if((bb==y&&cc==x) | | (bb==x&&cc==y))return true; }    return false;}intIsvanish (stringSintXintYintz) {    intcount[3]={0}; intc, I;  for(i=0; I<s.size (); i++)    {        if(s[i]=='R') c=0; Else if(s[i]=='Y') c=1; Else if(s[i]=='B') c=2; COUNT[C]++; if(Isvanish (x, Y, Z, count[0], count[1], count[2]))            returni+1; }    return 0;}intLongest (intVanishintLeftball) {    returnVanish>leftball?Vanish:leftball;}

Summary

To learn to separate the functions, do not always consider the whole.

Part of the part is implemented as a step, which helps to quickly and effectively question a.

hihocoder--Microsoft online Written test T1

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.