Why do I get Wrong Answer?

,

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[i] = sc1.nextLine();

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

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

CodeChef: Practical coding for everyone please check this is correct answer given for every input but why shoe wa??? ple check

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=n*fact(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[i]);
if((a[i]>=1)&&(a[i]<=100))
ans[i]=fact(a[i]);
}
for(i=0;i<t;i++)
printf("%d\n",ans[i]);

return 0;
}

#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???

you sshould use endl ornewline statement…

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[i]*j)+carry;
if(temp>9)
{
digit[i]=temp%10;
carry=temp/10;
}
else if(temp<=9)
{
digit[i]=temp;
carry=0;
}
}
}
int v=500;
while(digit[v]==0)
{
v–;
}
for(k=v;k>=0;k–)
{
printf("%d",digit[k]);
}
printf("\n");
}
return 0;
}
the code even works for much larger factorials…dont know why it isnt accepted…pls help…

#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

#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\n",q+1);
		break;
	}
	}
}
return 0;

}

why is it display wromg answer

COINS Problem - CodeChef is the question for which i have written a code CodeChef: Practical coding for everyone . 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 TLG Problem - CodeChef

#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?

2 Likes

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<<"\nInput\n";

cin>>x>>y;

cout<<"\nOutput\n";

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[i])
                {
                    k=j+1;
                    c++;
                    break;
                }
            }
        }
 if(c==n1)printf("\n Yes");
 else printf("\n 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[i][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[i][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\n “);
scanf(”%d”,&x);
if((x%5)!= 0)
printf("\n\nOutput\n %2f “,y);
else
{
if(x>=y)
printf(”\n\nOutput\n %2f",y);
else
{
x=x+0.50;
y=y-x;
printf("\n\nOutput\n %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++;
}


i=0;
while(i<T)
{
    for(j=0;str[i][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[i][c]==str[i][k])
                    {
                        str[i][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[i][c]==str[i][k])
                    {
                        str[i][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[i];

for(i=0;i<t;i++)
{
  while(j<=a[i])
  {
  	 f=f*j;
  	 j++;
  }
  cout<<"\nthe 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[i]);
for(i=0;i<n;i++)
{
count=0;
for(j=0;j<n;j++)
{
if(a[i]==a[j])
count++;
}
ar[i]=count;
}
max=ar[0];
for(i=1;i<n;i++)
{
if(max<ar[i])
max=ar[i];
}
for(i=0;i<n;i++)
{
if(ar[i]==max)
{
break;
}
}
p=a[i];
printf("%d %d\n",p,max);

}



return 0;

}