【CodeChef】Holes in the text
来源:互联网 发布:淘宝商城地下城装备 编辑:程序博客网 时间:2024/06/07 17:02
Problem here
All submissions for this problem are available.
Problem
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
Solution
#include <iostream>#include <string>using namespace std;char tex[] = {'A', 'B', 'D', 'O', 'P', 'Q', 'R', 'a', 'b', 'd', 'e', 'g', 'o', 'p', 'q'};int main(){ int n; while(cin >> n){ while(n--){ string input; int count = 0; cin >> input; for(int i = 0; i < input.length(); i++){ for(int j = 0; j < sizeof(tex); j++){ if(input[i] == tex[j]){ count++; if(input[i] == 'B'){ count++; } } } } cout << count << endl; } } return 0;}
- 【CodeChef】Holes in the text
- codechef Holes in the text 题解
- codechef - Discrepancies in the Voters List 题解
- 'holes' in files
- Halcon Measure the distance between the holes
- codechef The Army
- Codechef Reach The Point
- (codechef)The Next Palindrome
- CODECHEF Fill The Matrix
- Data Structures in the Andrew Text Editor
- The Cairo graphics tutorial -------Text in Cairo
- make the label text wrap in the gridview
- codechef The Lead Game 题解
- codechef The Morning Commute 题解
- codechef Closing the Tweets 题解
- 【Codechef】Tiptoe through the tulips
- 【CodeChef】 Queries on the String
- CodeChef Protecting The Poison【贪心】
- linux下静态库编译使用复杂版
- LeetCode题解:Path Sum
- nltk(1)——常用函数
- ZigBee中协调器断电重连问题?
- 4.2.2.6 android中检测网络连接状态简单总结
- 【CodeChef】Holes in the text
- Points in Segments (II)(线段树)
- iterator与const_iterator及const iterator区别
- 欢迎使用CSDN-markdown编辑器
- spark源码学习(八):spark具体是如何使用集群的资源去运行任务
- 005_Http之request获取客户端信息07-编码之response编码
- Scalaz(28)- ST Monad :FP方式适用变量
- 面试准备之catalan数相
- 监控 Linux 性能的 18 个命令行工具