Codeforces 518B. Tanya and Postcard

Source: Internet
Author: User

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

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.