Test instructions: Given the string s and T, if T has exactly the same letter as S, the number is equal to or more than S, the number of S is added to the yay! The answer is less than the number of words in t, and if T has the same letter as s but the case does not correspond (for example, a-a,z-z), it is added to the whoops answer.
Problem-Solving ideas: Open two size 52 array cs[],ct[], respectively, the number of letters A~Z and a~z, traversing two strings, so that the CS,CT array has a value
Iterate through two arrays, add the minimum value of the data stored in the two arrays to the YAY variable when the same subscript (for example, I), and subtract the minimum value from the cs[i],ct[i], respectively;
Traverse the 26~51 of the 0~25,CT array of the CS array, adding the minimum value of the data stored in the two arrays to the whoop variable when the same subscript (for example, i)
Traversing the 26~51 of the 0~25,cs array of the CT array, adding the minimum value of the data stored in the two arrays to the whoop variable when the same subscript (for example i)
The code is as follows:
1#include <stdio.h>2#include <iostream>3#include <algorithm>4#include <string.h>5 using namespacestd;6 #defineMaxLen 2000017 #defineN 528 CharS[maxlen],t[maxlen];9 intCs[n],ct[n];Ten intGetIDCharch) { One if(ch>='a'&&ch<='Z') A returnch-'a'; - Else - returnch-'A'+ -; the } - intMain () - { - intls,lt; + while(SCANF ("%s%s", s,t)! =EOF) { - GetChar (); +ls=strlen (s); Alt=strlen (t); atMemset (CS,0,sizeof(CS)); - for(intI=0; i<ls;i++){ -Cs[getid (S[i])]+=1; - } -memset (CT,0,sizeof(CT)); - for(intI=0; i<lt;i++){ inCt[getid (T[i])]+=1; - } to intyay=0, whoop=0; + intp; - for(intI=0; i<n;i++){ thep=min (cs[i],ct[i]); *cs[i]-=p; $ct[i]-=p;Panax Notoginsengyay+=p; - } the for(intI=0;i< -; i++){ +P=min (Cs[i], ct[i+ -]) + min (cs[i+ -], ct[i]); Awhoop+=p; the } +printf"%d%d\n", yay,whoop); - } $ return 0; $}
Codeforces 518B. Tanya and postcard