You are not logged in. Please login at www.codechef.com to post your questions!

×

HOLE IN THE TEXT

i using c++ what is the problem with my code it is showing wrong answer

#include<iostream>
#include<string>
using namespace std;
int holecount(char one);
int main()
{
int i,j,k;
int n,num=0;
cin>>n;

for(i=0;i<n;i++)
{
string str;
cin>>str;
for(j=0;j<str.length;j++)
{

 num+= holecount(str[j]);

}
cout<<num;
num=0;
}
return 0;
}
int holecount(char one)
{
    switch (one)
    {

        case 'A': return 1;
        break;
            case 'B': return 2;
        break;
            case 'C': return 0;
        break;
            case 'D': return 1;
        break;
            case 'E': return 0;
        break;
            case 'F': return 0;
        break;
            case 'G': return 0;
        break;
            case 'H': return 0;
        break;
            case 'I': return 0;
        break;
            case 'J': return 0;
        break;
            case 'K': return 0;
        break;
            case 'L': return 0;
        break;
            case 'M': return 0;
        break;
            case 'N': return 0;
        break;
            case 'O': return 1;
        break;
            case 'P': return 1;
        break;
            case 'Q': return 1;
        break;
            case 'R': return 1;
        break;
            case 'S': return 0;
        break;
            case 'T': return 0;
        break;
            case 'U': return 0;
        break;
            case 'V': return 0;
        break;
            case 'W': return 0;
        break;
            case 'X': return 0;
        break;
            case 'Y': return 0;
        break;
            case 'Z': return 0;
        break;
        default : return 0;
        break;
    }
}

asked 16 Nov '14, 15:59

k_biplav's gravatar image

1★k_biplav
12
accept rate: 0%

edited 16 Nov '14, 17:50

betlista's gravatar image

3★betlista ♦♦
16.9k49115225


I think your algo will be shorter if your switch statement will just check only for letters A B D O P Q R

link

answered 16 Nov '14, 17:29

ramher237's gravatar image

2★ramher237
1351619
accept rate: 28%

Yes, it is an improvement, but it is not a problem... Also combibation of return and break is strange.

(16 Nov '14, 17:58) betlista ♦♦3★

Your code cannot be compiled, probably you lost () for length during the copy and paste operation.

Your code returns 12 for input

2
A
B
link

answered 16 Nov '14, 17:58

betlista's gravatar image

3★betlista ♦♦
16.9k49115225
accept rate: 11%

As given in output format, output of each test case must be printed on individual single line. So print a '\n' after printing the answer for each case. Change the statement to cout<<num<<endl;

link

answered 16 Nov '14, 19:09

vinayawsm's gravatar image

4★vinayawsm
1.9k21430
accept rate: 24%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×856
×690
×643
×355
×205

question asked: 16 Nov '14, 15:59

question was seen: 851 times

last updated: 16 Nov '14, 19:09