Why do I get Wrong Answer?

faq
wa

#1

Why is my program getting wrong answer?


#2

Wrong answer means simply that - your program is not printing out the correct answer. You will just have to debug your program very carefully! Make sure your program is conforming exactly to the output format required, and not printing out unnecessary information, as mentioned at the start of this FAQ. Read below for a couple of other common issues that may lead to a Wrong Answer. You can also read here to find out some reasons for WA and their fixes.


#3

include

using namespace std;
int main(){
int i;
cin >> i;
while(i != 42){
cout << i;
cin >> i;
}
return(0);

}
Its showing wrong answer.why is it so?

#4

You should print ’
’ after each output.

include <iostream>

using namespace std;
 int main(){ 
int i; cin >> i;
 while(i != 42){
   cout << i<<endl;
   cin >> i; 
  } 
   return(0);
}

#5
#include 
using namespace std ;

int main(){

	int N ;
	cin >> N ;
	while(N!=42){
		cout << N <> N ;
	}
	return 0;
}

same code got Ac with this endl statement …


#6

thank you very much


#7

#include<stdio.h>
int main()
{
int x,i,j;
int a[99];
printf(“how many num you want to enter”);
scanf("%d",&x);
for(i=0;i<x;i++)
{
scanf("%d",&a*);
}
for(i=0;i<x;i++)
{
if(a*!=42)
printf("%d
",a*);
else
exit(1);
}
return 0;
}


#8

import re
import math
def function(n):
i=1
sum1=1
while n:
x=math.pow(i,i)
sum1=sum1*x
i=i+1
n=n-1
sum1=int(sum1)
return sum1
def main():
sum3=0#to calculate the sum of n testcases
sum2=0
d=list()
t=int(raw_input(’’))
while t>0:
n=int(raw_input(’’))
m=int(raw_input(’’))
q=int(raw_input(’’))
try:
if n>2 and n<100001:
sum3=sum3+n
if m>1 and m<1000000001:
while q>0:
r=int(raw_input(’’))
if r>1 and r<n:
sum2=sum2+r
fu=(function®*function(n-r))
f=function(n)/fu
res = f%m
d=res
print res
q=q-1

            except:
                    Z=1 
            t=t-1 
            return 0                                      

if name==“main”:
main()

why am i getting wrong answer on this code in pythhon
problem-easy-fambinatorial


#9

I am able to get all the answers for the sample inputs given in the problem. But still I get “Wrong answer”.


#10

You might be missing a few other conditions, always check your program for many different conditions. Also if in your output you give something like " The answer is 3 ", instead of simply outputting 3, you will get a wrong answer.

Its best to show your code and then ask.


#11

Hi Arun,

Is it ok for me to show the entire code? It’s from one of the challenges problem


#12

import java.util.Scanner;
class ChefChain
{
void compute()
{
try
{
int count1 =0,count2=0;
Scanner sc = new Scanner(System.in);
Scanner sc1 = new Scanner(System.in);
int t = sc.nextInt();
String s[] = new String[t];

int a1[] = new int[t];
for(int i = 0;i<t;i++)
{
s* = sc1.nextLine();

for(int j=0;j<s*.length();j++)
{
if(j%2==0)
{
if(s*.charAt(j)!=’+’)
{
count1++;
}
if(s*.charAt(j)!=’-’)
{
count2++;
}
}
else
{
if(s*.charAt(j)!=’-’)
{
count1++;
}
if(s*.charAt(j)!=’+’)
{
count2++;
}
}
}
if(count1<=count2)
{
a1* = count1;
}
else
{
a1* = count2;
}
count1 = 0;
count2 = 0;
}
for(int i=0;i<a1.length;i++)
{
if(i>0)
System.out.println();
System.out.print(a1*);
}

}
catch(Exception e)
{
}
}
public static void main(String args[])
{
new ChefChain().compute();
}
}
this show wrong answer… what shud i do


#13

http://www.codechef.com/viewsolution/6486351 please check this is correct answer given for every input but why shoe wa??? ple check


#14

tell me whats wrong in this program of finding factorials of small numbers
i am getting as wrong answer
#include<stdio.h>
int fact(int n)
{
int a;
if(n==0)
a=1;
else
a=nfact(n-1);
return a;
}
int main()
{
int i,t,a[100],ans[100];
scanf("%d",&t);
for(i=0;i<t;i++)
{
scanf("%d",&a
);
if((a*>=1)&&(a*<=100))
ans*=fact(a*);
}
for(i=0;i<t;i++)
printf("%d
",ans*);

return 0;
}


#15

#include<stdio.h>

void main()

{int n;
scanf("%d",&n);
while(n!=42)

{
if(n!=42)
printf("%d",n);
scanf("%d",&n);

}
}

what is wrong in this code???


#16

you sshould use endl ornewline statement…


#17

wasted hours rechecking my code…still cant figure out what’s wrong…
here’s my code for problem small factorials aka FCTRL2…

include < stdio.h>

int main()
{
int carry,i,j,n,m,l,sum,k;
sum=0;
scanf("%d",&n);
int num[101]={0};
for( m=0 ;m < n;m++)
{
scanf("%d",&num[m]);
}
for(l=0;l < n;l++)
{
int digit[501]={0};
digit[0]=1;
int temp;
for(j=2;j<=num[l];j++)
{
for(i=0;i<500;i++)
{
temp=(digit**j)+carry;
if(temp>9)
{
digit*=temp%10;
carry=temp/10;
}
else if(temp<=9)
{
digit*=temp;
carry=0;
}
}
}
int v=500;
while(digit[v]==0)
{
v–;
}
for(k=v;k>=0;k–)
{
printf("%d",digit[k]);
}
printf("
");
}
return 0;
}
the code even works for much larger factorials…dont know why it isnt accepted…pls help…


#18

#include <stdio.h>
int main()

{int i,n;

for(i=0;;i++)

{scanf("%d",&n);

if(n==42)

break;

printf("%d",n);

}

return 0;

}

why does it show wrong answer


#19

#include<stdio.h>
int main()
{
int t,n,temp,i,j,k,l,m,p,q;
scanf("%d",&t);
for(i=0;i<t;i++)
{
scanf("%d",&n);
int a[n];
for(j=0;j<n;j++)
{
scanf("%d",&a[j]);
}
scanf("%d",&k);
m=a[k-1];
for(l=0;l<n;l++)
{
for(p=0;p<n;p++)
{
if(a[p]>a[p+1])
{
temp=a[p+1];
a[p+1]=a[p];
a[p]=temp;

			}
		}
	}
	for(q=0;q<n;q++)
	{
		if(m==a[q]){
		
		printf("%d

",q+1);
break;
}
}
}
return 0;
}


#20

why is it display wromg answer