码迷,mamicode.com
首页 > 其他好文 > 详细

codechef Holes in the text 题解

时间:2014-05-03 15:49:18      阅读:412      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   class   code   ext   

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 integer T <= 40, the number of test cases. T test 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:
2
CODECHEF
DRINKEATCODE

Output:
2
5

简单的查找问题, 继续使用buffer解决本题。

#include <stdio.h>
#include <iostream>
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;
}



codechef Holes in the text 题解,布布扣,bubuko.com

codechef Holes in the text 题解

标签:des   style   blog   class   code   ext   

原文地址:http://blog.csdn.net/kenden23/article/details/24885845

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!