codechef Holes in the text 题解

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;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值