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