CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • June Long 2012
    • May Cook-Off
    • May Long 2012
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Practice(easy) » Holes in the text

Holes in the text

Problem code: HOLES

  • Submit
  • All Submissions

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


  • Submit

Comments

  • Login or Register to post a comment.

#include<stdio.h>   int

jaipurchamp_1 @ 24 Jan 2011 06:06 PM

#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

jaipurchamp_1 @ 24 Jan 2011 06:18 PM

#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

srinu_doki @ 27 Jan 2011 03:56 PM

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

road @ 28 Jan 2011 12:14 AM

To

Pratyush Kulwal

output format error:

printf("%d",cnt);


correction:

printf("%dn",cnt);

#include<stdio.h>#include<con

tiyashbasu @ 26 Feb 2011 03:48 PM

#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

bayer_villager @ 17 Mar 2011 12:22 AM

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

manoharsingh23 @ 22 Mar 2011 11:30 AM

@Gunjit: Use "cout<<r<<endl;" instead of just "cout<<r;"

I submitted two

ronakag @ 12 May 2011 10:33 PM

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

sivanraj @ 26 May 2011 06:03 PM
how i can participate

Why does it show TLE if I use

ashutosh30492 @ 15 Jun 2011 03:15 PM
Why does it show TLE if I use getchar() and process each character until a NULL is entered? And works if I take input as a string?

@ashutosh30492: NULL is

balajiganapath @ 16 Jun 2011 06:35 PM
@ashutosh30492: NULL is entered? How can a NULL be entered?

Sorry.. a new line character

ashutosh30492 @ 14 Jul 2011 01:24 PM
Sorry.. a new line character

#include #include #include i

venkat5485 @ 14 Sep 2011 12:54 PM
#include #include #include int main(void) { int n, i, hole, count=0; 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; 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(); } Execute t+his.. dis might help..

#include #include #include

venkat5485 @ 14 Sep 2011 12:54 PM
#include #include #include

the letters which have to be

nitishmittal @ 24 Sep 2011 02:47 AM
the letters which have to be considered is the input one only,or we have to cover every alphabet

The length of the text is

vonka @ 31 Dec 2011 04:18 AM
The length of the text is less then 100 is wrong it should be 1000

#!/usr/bin/env python test =

fers_1 @ 11 Jan 2012 10:50 AM
#!/usr/bin/env python test = input("Test:") case = [] out = [] for i in range(test): text = raw_input("Text Line: ") t = 0 for c in text: if c == "A" or c == "D" or c == "O" or c == "P" or c == "R" : t = t + 1 elif c == "B": t = t + 2 out.append(t) for res in out: print res

#include #include int main (

k_apil @ 11 Mar 2012 06:21 PM
#include #include int main ( ) { char p[100]; int a,t,i,l,c,c1; scanf("%d",&t); while(t--) { c=0,c1=0; printf("nenter the stringn"); scanf("%s",p); l = strlen(p); for(i=0;i

#include #include int main (

k_apil @ 11 Mar 2012 06:22 PM
#include #include int main ( ) { char p[100]; int a,t,i,l,c,c1; scanf("%d",&t); while(t--) { c=0,c1=0; printf("nenter the stringn"); scanf("%s",p); l = strlen(p); for(i=0;i

using System; static class

vipul4vb @ 14 Mar 2012 12:49 PM
using System; static class Program { static void Main(string[] args) { uint[] holeNums=new uint[Convert.ToUInt32(Console.ReadLine())]; uint i; for ( i= 0; i

@Admin: what's wrong with

vipul4vb @ 14 Mar 2012 12:51 PM
@Admin: what's wrong with this solution??? All my test cases (including sample test case) are resluting perfect. Please help me understand the error point. http://www.codechef.com/viewsolution/911703

None of my submissions seem

facetoe @ 24 Mar 2012 08:06 PM
None of my submissions seem to work... Here's my Ruby code: def get_in(num) arr = [] num.times do arr << gets.chomp end arr end def count_holes(arr) count = 0 final = [] arr.each do |el| el.split('').each do |lett| if ! lett.scan(/[POADRB]/).empty? count += 1 end end final << count count = 0 end final.delete_if {|a| a == 0} final.reverse end puts count_holes(get_in(gets.chomp.to_i)) Any idea why?

what is wrong with my

rishabhkumar66 @ 8 Apr 2012 01:45 PM
what is wrong with my code #include int main() { int n,c=0,i,j; char a[100]; scanf("%d",&n); for(i=0;i

plzzz tell me what is

rishabhkumar66 @ 8 Apr 2012 01:50 PM
plzzz tell me what is wrong.....it wrok successfully in my system(c free) rply soon...

http://ideone.com/BZIvS ,

ddacot @ 15 Apr 2012 10:58 PM
http://ideone.com/BZIvS , what's wrong? it works fine on my pc.

@ddacot : check for 'Q' as

jigsaw004 @ 13 May 2012 10:10 PM
@ddacot : check for 'Q' as well

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold

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.

CodeChef is a global programming communityCodeChef hosts online programming competitions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com