Problem: Holes ; Below is the code I am trying to execute but the compiler keeps giving me a WA . Could anyone help me find whats wrong ?

#include
#include<string.h>

using namespace std;
int main()
    {
    int i,test,length; int count =0;
    char a[100];
    cin>>test;
    while(test--)
        {
        cin>>a;
        	length=strlen(a);
            for(i=0;i<length;i++)
        {
            if(a[i]=='A'||a[i]=='D'||a[i]=='O'||a[i]=='P'||a[i]=='Q'||a[i]=='R')

                {
                    ++count;
                }

                if (a[i]== 'B')
                {
                   count= count + 2;
                }

        }
        }

        cout<<count ;
    }

You didn’t test your code properly, it’s giving wrong answer for input from problem statement - JeA4jE - Online C++ Compiler & Debugging Tool - Ideone.com

1 Like

And it is obvious, isn’t it? You have failed to initialize your count (each time, per test case).

@navkiran mahajan you are doing two things wrong.

  1. count value not resetting to zero for each test case.

  2. and you are printing count only one time.

You have to print count value for each test case and reset as well. Here, is the correct


[1].


  [1]: http://ideone.com/hFFcgm
1 Like

@shobagya sry to bug you. However i need help again . Would you mind checking what is wrong. I have checked sample input. It works fine albeit getting wrong answer over here ?

#include <iostream>
#include "stdio.h"
using namespace std ;
int main()
{    int test,x,y,z,w,lead,max=0;

    cin>>test;
    if (test>10000)
        exit(1);

    while(test--)
    {
        int sc1=0 ,sc2=0 ;
        cin>> x >> y ;
        if ((x<0)||(x>1000)|| (y<0)||(y>1000))
            return(0);
        sc1+=x; sc2+=y;
        if(sc1>sc2)
            {
            w=1;lead=sc1-sc2;
            }
        else
           if ( sc2>sc1)
            {
            w=2; lead=sc2-sc1;
            }
         else
                continue;
         if(lead>max)
         {
             max=lead;
             z=w;
         }

        }
        cout<<z<<" "<<max;
     return (0);
}

And for completeness, adding a return 0; will be great as well.

2 Likes

@tijoforyou yes :slight_smile:

thanks shobhagya

One more query for sake of completeness

Shall i convert the user input to Uppercase or would it suffice ?

@navkiran mahajan no need to do that. Since, it is already given that input is in upper case.

But this is different problem, isn’t it? It’s not holes… Create new thread and describe your approach briefly additionally to your code…

2 Likes

agree with @betlista ask it in a new thread with insights.