Codechef Holes in the text

Source: Internet
Author: User

Chef wrote some text on a piece of paper and now he wants to know how many holes are in the text. What is a hole? If you think of the paper as the plane and a letter as a curve on the plane, then each letter divides the plane into regions. for example letters "A", "D", "O", "P", "R" divide the plane into two regions so we say these letters each have one hole. similarly, letter "B" has two holes and letters such as "C", "E", "F", "K" have no holes. we say that the number of holes in the text is equal to the total number of holes in the letters of the text. help Chef to determine how many holes are in the text.

Input

The first line contains a single integerT <= 40, The number of test cases.TTest cases follow. the only line of each test case contains a non-empty text composed only of uppercase letters of English alphabet. the length of the text is less then 100. there are no any spaces in the input.

Output

For each test case, output a single line containing the number of holes in the corresponding text.

Example
Input:2CODECHEFDRINKEATCODEOutput:25

Simply find the problem and continue to use buffer to solve the problem.

#include 
 
  #include 
  
   using namespace std;int Holesinthetext(){int T, c = 0, ho = 0;scanf("%d\n", &T);char buffer[4000];char holes[7] = {'A','D','O', 'R', 'P', 'B', 'Q'};while ((c = fread(buffer, 1, 4000, stdin)) > 0){for (int i = 0; i < c; i++){if (buffer[i] == '\n'){printf("%d\n", ho);ho = 0;}else{for (int j = 0; j < 7; j++){if (buffer[i] == holes[j]) ho++;}if (buffer[i] == 'B') ho++;}}}if (ho != 0) printf("%d", ho);return 0;}
  
 



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.