Why do I get Wrong Answer?

,

#include
#include
using namespace std;

int main() {
	
int n[10];

for(int a = 0; a<10; a++)
{
	cin>>n[a];
}
for(int x = 0; x <10; x++){
	if (n[x]==42)
	break;
	else	{
		cout<<n[x]<<"\n";
	}
}
	return 0;
}

Why do I get wrong answer? However the program runs perfectly on local machine but on codechef it says wrong answer! Please help.

This is my code in python3 for beginner COLOUR problem and it gives correct answer for all sample input. But still the result is “Wrong answer”?

t=int(input())                                                              #no. of test cases
while t>0:
    n=int(input())                                                          #no of rooms in chef's house
    s=str(input())                                                          #colour config
    mnr=0
    cr=0
    cb=0
    cg=0
    for st in s:
        if st=="R" or st=="B" or st=="G":
            if st=="R":
                    cr+=1
            elif st=="B":
                    cb+=1
            elif st=="G":
                    cg+=1
    if cr==cb and cr==cg:
        mnr=cr*2
    else:
        mnr=n-max(cr,cb,cr)
    print(mnr)
    t-=1

I’ve tried to find answer to your problem. Test your program by some custom test cases and check the output, the results show why your program isn’t passing all test cases. I hope you can fix them by yourself. For more reference seek help from custom essay writing service.

thanks you friend

#include
using namespace std;
int main()
{
string s;
int n,k;

cin>>k;
for(int j=0;j<k;j++)
{

cin>>s;
n=s.size();
for(int i=n;i>=0;i--)
    cout<<s[i];
cout<<"\n";
}

}

I’ve tested the code but it gives me a wrong answer can anyone tell me why??

#include
#include
using namespace std;

int main() {

long long int t,i,n,w,c;

// your code goes here

cin>>t;



while(t--)

{c=0;
      cin>>n;

   char a[n],b[n];

  long long  int w[n+1];

    
    for(i=0;i<n;i++)

   { cin>>a[i];
   if(a[i]<65||a[i]>90)
   a[i]='_';
   }
  
    for(i=0;i<n;i++)

    { cin>>b[i];
   if(a[i]<65||a[i]>90)
   a[i]='_';
   }

    for(i=0;i<(n+1);i++)

    cin>>w[i];
   

    for(i=0;i<n;i++)

    {

    if(a[i]==b[i])

    c++;

    }
    cout<<w[c]<<endl;

}
return 0;
}

Why am I getting wrong answer?

Why am I getting a wrong answer?

#include
#include
using namespace std;
int main()
{
int a ;
double b;
cin >> a>> b;
if ((0< a<=2000) &&(0<=b<=2000) && (a <= b ))
{
if( a % 5 == 0 )

	cout <<fixed << setprecision(2)<<  b - a - 0.50 << "\n" ;

else 
     cout << fixed << setprecision(2) << b << "\n";

}
else
cout << fixed << setprecision(2) << b<< “\n”;
}

why m i getting wrong answer in this …question code CLEANUP?

#include<stdio.h>
main()
{
int T,t,n,m,i,k,N[1000],j,flag,chef[1000],asst[1000],x;
scanf("%d",&t);
for (T=0;T<t;T++)
{
scanf("%d",&n);
scanf("%d",&m);
for(i=0;i<=n-1;i++)
{
N[i]=1;
}

   for(i=0;i<=m-1;i++)
   {
         scanf("%d",&x);
         N[x-1]=0;
         
       }
   flag=0;
   k=0;
   j=0;
   for(i=0;i<=n-1;i++)
   {
        if(N[i]==1)
        {
           if(flag==0)
           {
           chef[k]=i+1;
           k++;
           flag=1;        
           }
           else
           {
            asst[j]=i+1;
           j++;
           flag=0;  
          }
        }
   }
    for(i=0;i<=k-1;i++)
     {
        printf("%d",chef[i]);
     }
     printf("\n");
    for(i=0;i<=j-1;i++)
     {
        printf("%d",asst[i]);
     }
     printf("\n");
  }
   return 0;

}

#include<stdio.h>
#include<stdlib.h>
int main()
{
long long t,n,i,j,m,s,x,o,a,b;
scanf("%lld",&t);
while(t–)
{
o=0;
scanf("%lld",&n);
char A[n];
long long B[n];
scanf("%s",A);
for(i=0;i<n;i++)
scanf("%lld",&B[i]);
for(i=0;i<n;i++)
{
m=100000000;
if(A[i]==48)
{
for(j=0;j<n;j++)
{
if(A[j]==49)
{
s=abs(B[j]-B[i]);
if(m>s)
{
m=s;
x=j;
}
}
}
o+=abs(B[x]-B[i]);
A[i]=49;
}
}
printf("%lld\n",o);
}
return 0;
}
why i get WA

#include<stdio.h>
int main(){
int t,n;
int a[200];

scanf("%d",&t);
while(t–){
scanf("%d",&n);
int temp=0;
int i=2;
a[0]=1;
int m=1;
int x;
while(i<=n){
int index=0;
while(index<m){
x=a[index]*i+temp;
a[index]=x%10;
temp=x/10;
index++;
}
while(temp!=0){
x=temp%10;
a[index]=x;
temp=temp/10;
m++;
index++;
}
i++;

}
int k;
for( k=m-1;k>=0;k–)
printf("%d",a[k]);

}

}

Why my answers is wrong ??

#include
using namespace std;

int main()
{
int x;
float y;
cin>>x>>y;
if(x%5!=0 || x>=y)
{
cout<<y<<endl;
}

else if(x%5==0)
{
    cout<<y-x-0.5<<endl;
}

return 0;

}
why am i getting wrong answer?

Check this code for this problem - Ice Cream Problem
Working perfectly for sample example - My Solution

why i get wrong answer

#include<stdio.h>
main()
{
int a[100];
int cnt=0,i=0,j=0;
printf(“enter no of digit”);
scanf("%d",&j);
printf(“enter”);
for(i=0;i<=j;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<=j;i++)
{
if(a[i]!=42)
printf("%d",a[i]);
else
break;
}
}
what is wrong with this code???

#include <stdio.h>
#include <string.h>

int main(void)
{
int T;
int win = 0;
int lose = 0;
char S[100];

do 
{
    scanf("%d",&T);
}
while ( T < 0 || T > 1000);

for(int j = 0; j < T;j++)
{
scanf("%s",S);

for(int i = 0; i < strlen(S); i++)
{
    if(S[i] != '1')
        ++lose;
    else
        ++win;
}

if (win > lose)
    printf("WIN\n");
else
    printf("LOSE\n");

}
 return 0;   
}

why WA ?

import java.util.*;
class cd2
{
public static void main(String ar[])
{
Scanner s=new Scanner(System.in);
Long T,D;
T=s.nextLong();
while(T–!=0)
{
D=s.nextLong();
Long w,z;
w=(long)0;
z=(long)0;
while(D>0)
{
if(D%10==1)
w++;
else
z++;
D=D/10;
}
if((w==1)||(z==1))
System.out.println(“Yes”);
else
System.out.println(“No”);
}
}
}

It’s giving wrong answer.

I am able to get all the answers for the sample inputs given in the problem. But still I get “Wrong answer”.
my problem code is :: CHEFKEY and my answer code is below .

/*
			-----   Kiamottullah   -----
			       (20/ 10/ 2016)
			All code is written by me .
			You can allways use this code for
			Learning context . keep learning

*/

#include
#include
using namespace std;

class Pair{
private :
long long int X;
long long int Y;

public :
    Pair(int x, int y){
        X = x;
        Y = y;       // constructor
    }
    		// prototypes of this class
    int getX (){
        return X;
    }
    int getY (){
        return Y;
    }
    void show (){
        cout << getX() << " " << getY() << endl;
    }

};

class Testcase{
private :
int N; // height
int M; // width
long long int C; // number of colours

    vector <Pair> Pairs;    // it's pairs
    
public :
    Testcase (int n, int m, int c){
        N = n;
        M = m;      // constructor
        C = c;
        calculatePairs();
    }
    
    		// prototypes of this class
    int getN (){
        return N;
    }
    int getM (){
        return M;
    }
    int getC (){
        return C;
    }
    
    void calculatePairs (){
    // is all color (C) fit in (n*m) display
        if((N * M) >= C){
        
        	// firstly push two pairs (1, C) and (C, 1)
            int x = 1, y = C;
            if(isFit(x, y)){
                Pairs.push_back(Pair(x, y));
            }
            x = C, y = 1;
            if(isFit(x, y)){
                Pairs.push_back(Pair(x, y));
            }
            // checking all the pairs from 2 to C/2
            int hulf = C/2;
            for(int i = 2; i <= hulf; i++){		
                for(int j = 2; j <= C/i; j++){
                    if(isPair(i, j)){
                        if(isFit(i, j)){
                            Pairs.push_back(Pair(i, j));
                        }
                    }
                }
            }
        }else {
			        // so if all color can't drawble
			        // Pair size will be 0
        }
    }
    void showPairs (){
        int s = Pairs.size();	// this function show all the Pairs
        for(int i = 0;i < s; i++){	// of C ... one by one
            Pairs[i].show();
        }
    }
    bool isFit (int x, int y){
        if(((x <= N) && (y <= M))){
            return true;		// this function check whether 
        }else {			// A pair (rect) fit into display (n*m)
            return false;		  
        }
    }
    int getPairsLength (){
        return Pairs.size();	// this function return the number of 
    }				            // Pairs in Pairs vector .
    
    bool isPair (int x, int y){
        if ((x * y) == C){		// this function return true if (x*y) == C
            return true;		// else return false that's it ((x*y) != C)
        }else {
            return false;
        }
    }

};

int main() {
// number of test case;
int T;

// get input of number of test case
cin >> T;

// make an vector of size T;
vector <Testcase> cases;

for(int i = 0; i < T; i++){			// while (i < T) take input of
    int n, m, c;				// (n, m, c) for each testcase
    cin >> n >> m >> c;			// then push them in `cases`
    cases.push_back(Testcase(n, m, c));	// vector
}

for(int i = 0; i < cases.size(); i++){	// for each testcase `tc`
    Testcase tc = cases[i];			// cout the length of Pairs
    cout << tc.getPairsLength() << endl;
}
return 0;

}

One of the best way to handle the wrong ans type problems is that to generate random input by your’s side and then by computer side(By taking random inputs using rand() function in C or C++. It will make you to think more and you will definitely crack the crack the code ASAP…

I am getting the sample output correct but still getting wrong answer. Please help me find my mistake!

#include
using namespace std;
int main()
{ short t,e;
long m;
int k,n,i,j,key,marks;
cin>>t;
int a[10000]={0};
int arr[10001][4]={0};
for(;t>0;t–)
{
cin>>n>>k>>e>>m;
for(j=0;j<n;j++)
{
for(i=0;i<e;i++)
{ if(j==n-1&&i==e-1)
break;
else
{
cin>>arr[j][i];
a[j]+=arr[j][i];
}
}

    }
    
    for(i=1; i<n-1; i++)
    {
        key = a[i];
        j = i-1;
        while(j>=0 && key>a[j])
        {
            a[j+1] = a[j];
            j--;
        }
        a[j+1] = key;
    }
   
    marks=(a[k-1]+1)-a[n-1];
    if(marks<=m)
        if(marks>0)
            cout<<marks;
        else
            cout<<"0";
    else
        cout<<"Impossible ";
    
}
return 0;

}

For the problem- Chef Under Pressure, in the subtask 1, out of 10 tasks, it is showing wrong answer for task 0, rest all are coming correct. I checked for possible corner cases that i might have missed, but couldn’t find anything. Please tell me what is task 0 and its output, so that i can modify my code. Thanks