Holes in the textProblem code: HOLES |
All submissions for this problem are available.
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
| Author: | anton_lunyov |
| Date Added: | 13-01-2011 |
| Time Limit: | 1 sec |
| Source Limit: | 50000 Bytes |
| Languages: | ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC |
Comments
SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:
HELP
Program should read from standard input and write to standard output. After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:
- Accepted
Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark. - Time Limit Exceeded
Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach. - Wrong Answer
Your program compiled and ran succesfully but the output did not match the expected output. - Runtime Error
Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section. - Compilation Error
Your code was unable to compile. When you see this icon, click on it for more information.
If you are still having problems, see a sample solution here.

Fetching successful submissions

#include<stdio.h> int
#include<stdio.h>
int main()
{
int t,cnt=0,i;
char a[100];
scanf("%d",&t);
while(t--)
{
scanf("%s",a);
for(i=0;a[i]!=' ';i++)
{
if(a[i]=='P'||a[i]=='O'||a[i]=='A'||a[i]=='D'||a[i]=='R')
cnt++;
if(a[i]=='B')
cnt=cnt+2;
}
printf("%d",cnt);
cnt=0;
}
return 0;
}
seriously Frustrated ...its showing wrong answer.....
#include<stdio.h> #include<st
#include<stdio.h>
#include<string.h>
int main()
{
int t,cnt=0,i,n;
char a[100];
scanf("%d",&t);
while(t--)
{
scanf("%s",a);
n=strlen(a);
for(i=0;i<n;i++)
{
if(a[i]=='A'||a[i]=='D'||a[i]=='O'||a[i]=='P'||a[i]=='Q'||a[i]=='R')
cnt++;
if(a[i]=='B')
cnt=cnt+2;
}
printf("%d",cnt);
cnt=0;
}
return 0;
}
seriously what is wrong cant undersstand
import
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.Exception;
class Holesinthetext
{
public static void main(String args[])
{
int tc=0,cnt;
String strr=null;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try
{
tc=Integer.parseInt(br.readLine());
}
catch(Exception e){}
if(tc<41)
{
for(int i=0;i<tc;i++)
{
cnt=0;
try
{
strr=br.readLine();
}
catch(Exception e){}
int len=strr.length();
if(len<101)
{
char[] str=strr.toCharArray();
for(int j=0;j<len;j++)
{
if(str[i]=='A'||str[i]=='D'||str[i]=='O'||str[i]=='P'||str[i]=='Q'||str[i]=='R')
cnt++;
if(str[i]=='B')
cnt+=2;
}
System.out.println(cnt);
}
}
}
}
}
To Pratyush Kulwal output
To
Pratyush Kulwal
output format error:
printf("%d",cnt);
correction:
printf("%dn",cnt);
#include<stdio.h>#include<con
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main(void)
{
int n, i, hole, count;
char ch;
char* str[40][100];
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%s", str[i]);
for(i = 0; i < n; i++)
{
hole = count = 0;
ch = str[i][count];
while (ch != ' ')
{
ch = toupper(ch);
if (ch == 'A' || ch == 'D' || ch == 'O' || ch == 'P' || ch == 'Q' || ch == 'R')
hole++;
else if (ch == 'B')
hole += 2;
ch = str[i][++count];
}
printf("%dn", hole);
}
getch();
return 0;
}
someone please tell what is
someone please tell what is wrong with my code
http://www.codechef.com/viewsolution/490278
as it is running successfully on my system(devc++)
@Gunjit: Use "cout<<r<<endl;"
@Gunjit: Use "cout<<r<<endl;" instead of just "cout<<r;"
I submitted two
I submitted two soln
http://www.codechef.com/viewsolution/547862
http://www.codechef.com/viewsolution/547861
In Prog one i used cin to inout the string while in Prog Two i used scanf("%s",&a) to input the character..
Cin is working but scanf is showin me run time error why?
how i can participate
Why does it show TLE if I use
@ashutosh30492: NULL is
Sorry.. a new line character
#include #include #include i
#include #include #include
the letters which have to be
The length of the text is
#!/usr/bin/env python test =
#include #include int main (
#include #include int main (
using System; static class
@Admin: what's wrong with
None of my submissions seem
what is wrong with my
plzzz tell me what is
http://ideone.com/BZIvS ,
@ddacot : check for 'Q' as