Why do I get Wrong Answer?

http://www.codechef.com/problems/COINS is the question for which i have written a code http://www.codechef.com/viewsolution/6885244 . Kindly let me know why i am getting wrong answer??

I don’t understand.I am compiling in my system and also in ideone both are giving me same answer. But when I submit it in CodeChef it is showing wrong answer. Why is that happening?

Following is the code for the problem given here http://www.codechef.com/problems/TLG

#include<stdio.h>
int main()

{

int n,si,ti,w=0,l=0,i;

scanf("%d",&n);

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

	scanf("%d %d",&si,&ti);

	if(si>ti && l<(si-ti))
	{
		l=si-ti;
		 w=1;
	}
	else if(ti>si && l<(ti-si))
	{
		l=ti-si;
		w=2;
	}
	
}
printf("%d %d",w,l);
return 0;

}

Can anyone please tell me what’s wrong with it?

def repeat():
num=input(‘Enter number’)
if num!=42:
repeat()
print num
else:
return
repeat()

Why is it showing wrong answer??

Its giving wrong answer again and again
#include
#include
using namespace std;

int main() {

int x;
float y;

cout<<"

Input
";

cin>>x>>y;

cout<<"

Output
";

if ((x<y)&&(x%5==0))
y-=(x+0.50);
    cout<<fixed;
cout<<setprecision(2)<<y<<endl;
return 0;

}

it was long but had to cut short it to the above part, still I get a wrong answer.

What is wrong in this code?
I run this code in codeblocks and it is working fine but getting wrong answer in codechef.
#include<stdio.h>
int main()
{
int q,r,b=0,m,n,i,j,k,sum=0;
scanf("%d",&i);
if(i<=100)
{
while(i!=0)
{
i–;
scanf("%d",&m);
scanf("%d",&n);
j=m;
while(j<=n)
{
k=j;
q=j;
while(k>0)
{
r=k%10;
b=(b*10)+r;
k=k/10;
}
if(b==q)
{
sum=sum+b;

      }
      b=0;
      j++;
}
printf("%d",sum);
sum=0;

}
}
return 0;
}

please help

#include<stdio.h>
int main()
{
int t,n,n1,i,j,c,k;

scanf("%d",&t);
while(t)
{

 c=0;
scanf("%d",&n);
int s[n];
for(k=0;k<n;k++)
scanf("%d",&s[k]);

scanf("%d",&n1);
int f[n1];
for(k=0;k<n1;k++)
scanf("%d",&f[k]);

for(i=0;i<n1;i++)
        {
            for(j=k;j<n;j++)
            {
                if(s[j]==f*)
                {
                    k=j+1;
                    c++;
                    break;
                }
            }
        }
 if(c==n1)printf("

Yes");
else printf("
No");
t–;
}
return 0;
}

Why am I getting wrong answer for this code?

QUESTION :
Question ID : ACM14AM4
ISRO is planning to build a landing platform on MARS as a part of MOM. It has selected a small 2-D rectangular region for the same, and every point in the region has a strength associated with it. The landing platform should be in the form of a cross (see definition below for more details) and as strong as possible.

The selected 2-D rectangular region has M * N points represented by (x, y), for all 0 <= x < M, 0 <= y < N. Let W*[j] denote the strength of the point (i, j). We define a cross as follows:

It consists of 2 line segments of equal length. The end points of the line segments should coincide with any of the given M * N points.

Each of the line segments are at an angle of 45° with both the X & Y axis.

Both the line segments intersect exactly at one point, and their centres coincide. (i.e) if the 2 line segments are represented by { (x11, y11), (x12, y12) }, { (x21, y21), (x22, y22) }, then (x11+x12) / 2 = (x21+x22) / 2 and (y11+y12) / 2 = (y21+y22) / 2. The point where the 2 line segments intersect is called the center of the cross.

Each line segment of the cross should have a non-zero length. Hence, a single point cannot be considered as a cross.

The strength of a cross is defined as the sum of strengths of all points that lie on it. Your task is to find the cross with maximum strength, which ISRO would like to use as the landing platform.
Input

The first line contains an integer T, denoting the number of test cases.

Then for each test case, the first line contains two integers M and N.

Each of the following M lines, contain N space separated integers, where the jth integer on the ith line denotes W[i-1][j-1], for all 1 <= i <= M, 1 <= j <= N.
Output

For each test case, output a single integer denoting the strength of the maximum-strength cross, on a separate line
Constraints

T ≤ 100
2 ≤ M ≤ 100
2 ≤ N ≤ 100
-106 ≤ W*[j] ≤ 106

Example

Input:
2
3 3
-1 -1 1
-1 -1 -1
1 -1 -1
2 3
0 1 -2
2 3 1

Output:
-1
6

Explanation

In the first case, the cross formed by the line segments {(0, 0), (2, 2)} and {(0, 2), (2, 0)} has the maximum strength = 1+(-1)+1+(-1)+(-1) = -1. Note: You cannot choose a cross with 0 strength (not passing through any of the given points) here, because it is given that each line segment of the cross should pass through atleast one of the given points

In the second case, the cross formed by the line segments {(0, 0), (1, 1)} and {(0, 1), (1, 0)} has the maximum strength = 0+3+1+2 = 6

SOLUTION :
Solution ID :8466199

this code is giving wrong answer.
in g++ it is working good for all cases i thoghthmay be possible.
how can i correct it.

#include<stdio.h>
int main()
{
int x;
float y=20000.00;
printf(“input
“);
scanf(”%d”,&x);
if((x%5)!= 0)
printf("

Output
%2f “,y);
else
{
if(x>=y)
printf(”

Output
%2f",y);
else
{
x=x+0.50;
y=y-x;
printf("

Output
%2f",y);
}
}
return 0;
}

in this ATM code i am getting wrong answer even if the logic is correct!

GETTING WA :confused:

#include
using namespace std;

int main()
{
int T,i=0,j,mid,c,k,flag;
char str[100][1000];
cin>>T;

if(T>101 || T==0)
    return 0;
    
while(i<T) 
{
    cin>>str*;
    i++;
}


i=0;
while(i<T)
{
    for(j=0;str*[j]!='\0';++j);
    if(j<2 || j>1000)
        return 0;
    
    if(j%2==0)
    {
        mid=j/2;
        for(k=0;k<mid;++k)
        {   flag=0;
            for(c=mid;c<j;++c)
            {
                if(str*[c]==str*[k])
                    {
                        str*[c]='0';
                        flag=1;
                    }         
            }
            if(flag==0) 
                {
                    cout<<"NO"<<endl;
                    break;
                }
                
        }
        if(flag==1)
            cout<<"YES"<<endl;
    }
    else
    {
        mid=j/2;
        for(k=0;k<mid-1;++k)
        {   flag=0;
            for(c=mid+1;c<j;++c)
            {
                if(str*[c]==str*[k])
                    {
                        str*[c]='0';
                        flag=1;
                    }         
            }
            if(flag==0) 
                {
                    cout<<"NO"<<endl;
                    break;
                }         
                    
        }
        if(flag==1)
            cout<<"YES"<<endl;	        
    }
    i++;
}
return 0;	

}

#include
using namespace std;
int main()
{
int t,i,a[100];

int j=1,f=1;
cout<<"enter the no. of values you want to enter"<<endl;
cin>>t;
if(t<=100){

cout<<"enter the values in list"<<endl;
for(i=0;i<t;i++)
cin>>a*;

for(i=0;i<t;i++)
{
  while(j<=a*)
  {
  	 f=f*j;
  	 j++;
  }
  cout<<"

the factorial of given no. is"<<endl<<f;
}
}}

why I am getting wrong answer? :frowning:

#include<stdio.h>
int main()
{
int i,j,t,p,n,max,count;
int a[101]={0};
int ar[101]={0};
scanf("%d",&t);
while(t–)
{
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a*);
for(i=0;i<n;i++)
{
count=0;
for(j=0;j<n;j++)
{
if(a*==a[j])
count++;
}
ar*=count;
}
max=ar[0];
for(i=1;i<n;i++)
{
if(max<ar*)
max=ar*;
}
for(i=0;i<n;i++)
{
if(ar*==max)
{
break;
}
}
p=a*;
printf("%d %d
",p,max);

}



return 0;

}

why i am getting wrong answer?? I am getting right answer in eclipse ide

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;

class SGARDEN {

private static String[] s;

private static HashMap<Integer, Integer> hm;

private static long[] a;

private static ArrayList<Integer> a1;

public static void main(String args[]) throws NumberFormatException,
		IOException {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	int t = Integer.parseInt(br.readLine());
	a1 = new ArrayList<Integer>();
	for (int i = 0; i < t; i++) {
		int n = Integer.parseInt(br.readLine());
		a = new long[n];

		s = br.readLine().split(" ");
		hm = new HashMap<Integer, Integer>();
		for (int j = 1; j <= s.length; j++) {
			hm.put(j, Integer.parseInt(s[j - 1]));

		}
		for (int j = 1; j <= s.length; j++) {
			a[j - 1] = solve(j, j);
		}
		// System.out.println(Arrays.toString(a));
		a1.add((int) (lcm(a) % (10 ^ 9 + 7)));

	}
	for (int m : a1) {
		System.out.println(m);
	}
}

private static int solve(int j, int want) {
	// TODO Auto-generated method stub

	if (hm.get(j) == want) {
		return 1;
	}
	return solve(hm.get(j), want) + 1;

}

private static long lcm(long a, long b) {
	return a * (b / gcd(a, b));
}

private static long lcm(long[] input) {
	long result = input[0];
	for (int i = 1; i < input.length; i++)
		result = lcm(result, input*);
	return result;
}

private static long gcd(long a, long b) {
	while (b > 0) {
		long temp = b;
		b = a % b; // % is remainder
		a = temp;
	}
	return a;
}

private static long gcd(long[] input) {
	long result = input[0];
	for (int i = 1; i < input.length; i++)
		result = gcd(result, input*);
	return result;
}

}

#include <stdio.h>

int main(void)
{
int k,s,n,t,y;
scanf("%d",&t);
for(y=1;y<=t;y++)
{
scanf("%d",&n);
s=1;
for(k=1;k<=n;k++)
{
s=s*k;
}
printf("%d
",s);
}
return 0;
}

why am i getting wrong answer for this question?

print everything what you asked and specially take care of separators(like new line character or space), also do not print anything except you have asked.(for example don’t print like “how many num you want to enter”).
so you will not get Wrong ans except error in logic.

A WRONG ANSWER, REASONS and POSSIBLE DEBUGGING :-

  • Wrong function :- The most common reason for a wrong answer is usage of a wrong function. For example, if the problem wants you to add 3 integers but you have subtracted them, WRONG ANSWER!

  • Input-OutPut Format :- The output should be carefully formatted as chef wants everything neat and clean. Maximum of the answers are to be displayed with "
    " a new line and some require inputs require good spacing.

  • Logical Errors :- Well grab a 11th standard book and see what a logical error is and how it can’t be detected by the compiler. Making it a horrible error altogether.

        That is all folks!! HAPPY CODING!!

#include<stdio.h>
int main()
{
int t,i,flag=0;
char a[1000];
scanf("%d",&t);
while(t–)
{
scanf("%s",a);
for(i=0;i<1000;i++)
{
if(a*==‘I’)
{printf(“INDIAN”);
flag=1;
break;
}}
for(i=0;i<1000;i++)
{
if(a*==‘Y’)
{printf(“NOT INDIAN”);
flag=1;
break;
}}
if(flag==0)
printf(“NOT SURE”);
}return 0;}
this code gives perfectly right answers iam still getting wrong ans can anyone point out my mistake

#include
using namespace std;

int main()
{
int w;
float i,f;
cin>>w>>i;
if((w%5==0)&&(i>w)){
f=i-w-0.50;
cout<<f;
}
else
cout<<i;
return 0;
}

i’m getting a wrong answer in the ATM question and not allowed to ask a question, can anyone help me with this?

Anyone tell me plz whats wrong in this?
https://www.codechef.com/viewsolution/9360275

my program is right… i dont know why its always give wrong answer

#include<stdio.h>
int main()
{
unsigned int t,n,sum=0,x=0;
int count=0;
scanf("%d",&t);
while(t>0)
{
scanf("%d",&n);
x=n;
while(n>=1 && count==0)
{
if(n>=100)
{
n=x%100;
sum=sum+(x/100);
x=n;
}
else if(n>=50)
{
n=x%50;
sum=sum+(x/50);
x=n;
}
else if(n>=10)
{
n=x%10;
sum=sum+(x/10);
x=n;
}
else if(n>=5)
{
n=x%5;
sum=sum+(x/5);
x=n;
}
else if(n>=2)
{
n=x%2;
sum=sum+(x/2);
x=n;
}
else
{
sum=sum+1;
count++;
}
}
printf("%d
",sum);
sum=0;
t–;
}
return 0;
}

#include<stdio.h>
int main()
{
int t;int i,j;
int a[100];
long f;
scanf("%d",&t);
for(i=0;i<t;i++)
scanf("%d",&a*);
for(i=0;i<t;i++)
{
f=1;
for(j=1;j<=a*;j++)
{
f=f*j;
}
printf("%ld
",f);
}
return 0;
}

I have run this in visual studio…output is correct still it is giving wrong answer

question is this:
You are asked to calculate factorials of some small positive integers.

Input

An integer t, 1<=t<=100, denoting the number of testcases, followed by t lines, each containing a single integer n, 1<=n<=100.

Output

For each integer n given at input, display a line with the value of n!

Example

Sample input: 4
1
2
5
3

Sample output:
1
2
120
6