You are not logged in. Please login at www.codechef.com to post your questions!

×

Why do I get Wrong Answer?

1
1

Why is my program getting wrong answer?

asked 22 Mar '13, 16:31

anup's gravatar image

2★anup ♦♦
2.4k273944
accept rate: 21%


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.

link

answered 22 Mar '13, 16:32

admin's gravatar image

0★admin ♦♦
19.8k350498541
accept rate: 36%

edited 12 Aug '13, 16:33

Answer is hidden as author is suspended. Click here to view.

answered 04 Dec '16, 20:34

mohitkyadav's gravatar image

1★mohitkyadav
(suspended)
accept rate: 25%

just check out that your program is following the constraints given in the problem. try to take input just as the given in constraints. This will help you to determine whether your logic is correct or not. Hope this helps you!!

link

answered 02 Feb '17, 02:22

vikisahu's gravatar image

2★vikisahu
211
accept rate: 0%

include <iostream>

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

answered 02 Jan '15, 00:40

rohit2811995's gravatar image

2★rohit2811995
211
accept rate: 0%

1

Hey please add new line in your code in output section then you will surely get AC

(02 Jan '15, 00:46) ma5termind3★
1

Because You have missed "\n" after cout<<i statement.

(02 Jan '15, 00:49) damn_me3★

You should print '\n' after each output.

include <iostream>

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

answered 02 Jan '15, 00:46

aadil_ahmad's gravatar image

4★aadil_ahmad
296
accept rate: 0%

#include <bits stdc++.h="">
using namespace std ;

int main(){

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

same code got Ac with this endl statement ..

link

answered 02 Jan '15, 00:49

ma5termind's gravatar image

3★ma5termind
1.7k11730
accept rate: 11%

thank you very much

link

answered 11 Jan '15, 16:49

gaafer's gravatar image

0★gaafer
1
accept rate: 0%

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[i]); } for(i=0;i<x;i++) { if(a[i]!=42) printf("%d\n",a[i]); else exit(1); } return 0; }

link

answered 21 Jan '15, 00:22

kaanchi's gravatar image

3★kaanchi
1
accept rate: 0%

import re import math def function(n): i=1 sum1=1 while n: x=math.pow(i,i) sum1=sum1x 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(r)
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

link

answered 25 Jan '15, 20:48

p_gupta's gravatar image

1★p_gupta
1
accept rate: 0%

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

link

answered 08 Feb '15, 20:32

vrajendra_vt's gravatar image

2★vrajendra_vt
1
accept rate: 0%

1

Sample inputs are just public test cases but your code need to pass all the public as well as private test cases.you can follow this link for more info...https://www.quora.com/What-is-the-advice-you-would-give-a-beginner-whose-code-passes-all-public-test-cases-but-fails-around-40-50-of-test-cases

(22 Feb '17, 11:35) harry19954★

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.

link

answered 08 Feb '15, 20:48

arun_as's gravatar image

1★arun_as
7413618
accept rate: 10%

Hi Arun,

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

link

answered 09 Feb '15, 18:55

vrajendra_vt's gravatar image

2★vrajendra_vt
1
accept rate: 0%

if it's from a live contest u mustn't share it even if it's partial you may be disqualified for this

(07 Sep '16, 01:50) mahipalsaran3★

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&lt;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

link

answered 11 Feb '15, 01:11

shreyansh_1913's gravatar image

2★shreyansh_1913
1
accept rate: 0%

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

link

answered 13 Mar '15, 11:27

grb47's gravatar image

4★grb47
1
accept rate: 0%

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; }

link

answered 15 Mar '15, 11:26

karankapooria's gravatar image

0★karankapooria
1
accept rate: 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???

link

answered 17 Mar '15, 02:43

raunak287's gravatar image

1★raunak287
-1
accept rate: 0%

you sshould use endl ornewline statement...

link

answered 17 Mar '15, 03:51

ankit_srt's gravatar image

0★ankit_srt
1
accept rate: 0%

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..

link

answered 25 Mar '15, 20:31

agrwl's gravatar image

0★agrwl
11
accept rate: 0%

edited 25 Mar '15, 20:34

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

link

answered 18 Apr '15, 21:42

adarsh1994's gravatar image

0★adarsh1994
1
accept rate: 0%

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&lt;n;j++)" {="" scanf("%d",&a[j]);="" }="" scanf("%d",&k);="" m="a[k-1];" for(l="0;l&lt;n;l++)" {="" for(p="0;p&lt;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;

}

link

answered 19 Apr '15, 20:16

tushargarg's gravatar image

2★tushargarg
1
accept rate: 0%

why is it display wromg answer

link

answered 19 Apr '15, 20:17

tushargarg's gravatar image

2★tushargarg
1
accept rate: 0%

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

link

answered 12 May '15, 23:34

aakashbhat's gravatar image

2★aakashbhat
1122
accept rate: 0%

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?

link

answered 01 Jun '15, 22:33

write2diba's gravatar image

2★write2diba
311
accept rate: 0%

edited 01 Jun '15, 23:01

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

Why is it showing wrong answer??

link

answered 09 Sep '15, 00:36

vishesh9494's gravatar image

2★vishesh9494
1
accept rate: 0%

Its giving wrong answer again and again

include <iostream>

include<iomanip>

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.

link

answered 30 Sep '15, 22:54

venture_walk's gravatar image

4★venture_walk
11
accept rate: 0%

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

link

answered 03 Oct '15, 01:47

tushantb's gravatar image

0★tushantb
1
accept rate: 0%

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?

link

answered 03 Oct '15, 18:13

jyotsna_08's gravatar image

3★jyotsna_08
1
accept rate: 0%

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.

link

answered 09 Oct '15, 21:12

nilesh_2311's gravatar image

2★nilesh_2311
1
accept rate: 0%

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!

link

answered 11 Oct '15, 11:39

sam2698's gravatar image

0★sam2698
1
accept rate: 0%

GETTING WA :/

include <iostream>

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;

}

link

answered 18 Oct '15, 21:57

shivangi1404's gravatar image

2★shivangi1404
1
accept rate: 0%

include<iostream>

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? :(

link

answered 24 Oct '15, 21:05

apoorv_jain95's gravatar image

0★apoorv_jain95
1
accept rate: 0%

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;

}

link

answered 31 Oct '15, 23:34

manohar1408's gravatar image

0★manohar1408
1
accept rate: 0%

why is it showing wrong answer?

(31 Oct '15, 23:36) manohar14080★

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[i]);
    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[i]);
    return result;
}

}

link

answered 02 Nov '15, 15:11

sesy's gravatar image

0★sesy
1
accept rate: 0%

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\n",s); } return 0; }

why am i getting wrong answer for this question?

link

answered 11 Dec '15, 12:11

manvir21's gravatar image

1★manvir21
1
accept rate: 0%

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.

link

answered 11 Dec '15, 14:35

dhavalmehta's gravatar image

2★dhavalmehta
563
accept rate: 30%

edited 11 Dec '15, 14:36

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 "\n" 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!!
    
link

answered 12 Dec '15, 09:50

raj_epsilon's gravatar image

1★raj_epsilon
1
accept rate: 0%

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]=='I') {printf("INDIAN"); flag=1; break; }} for(i=0;i<1000;i++) { if(a[i]=='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

link
This answer is marked "community wiki".

answered 16 Dec '15, 23:49

priyanshu1998's gravatar image

0★priyanshu1998
1
accept rate: 0%

include <iostream>

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?

link

answered 09 Feb '16, 00:41

utkarshlearner's gravatar image

0★utkarshlearner
1
accept rate: 0%

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

link

answered 09 Feb '16, 14:58

vipkaushal21's gravatar image

0★vipkaushal21
1
accept rate: 0%

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\n",sum); sum=0; t--; } return 0; }

link

answered 21 Feb '16, 17:59

aky28's gravatar image

0★aky28
1
accept rate: 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[i]); for(i=0;i<t;i++) { f=1; for(j=1;j<=a[i];j++) { f=f*j; } printf("%ld\n",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

link

answered 28 Feb '16, 22:56

bharat_12's gravatar image

0★bharat_12
1
accept rate: 0%

#include <iostream>
#include <cstdio>
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.

link

answered 24 Apr '16, 23:03

char_star's gravatar image

0★char_star
1
accept rate: 0%

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
link

answered 29 Apr '16, 12:12

shivang_py's gravatar image

0★shivang_py
1
accept rate: 0%

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.

link

answered 30 Apr '16, 15:00

raygmurphy's gravatar image

0★raygmurphy
1
accept rate: 0%

thanks you friend

link

answered 01 May '16, 16:48

meight_888's gravatar image

0★meight_888
1
accept rate: 0%

include<iostream>

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

link

answered 07 May '16, 00:04

strangecoder_1's gravatar image

0★strangecoder_1
1
accept rate: 0%

include <iostream>

include <string>

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?

link

answered 11 May '16, 17:24

keertika32's gravatar image

0★keertika32
111
accept rate: 0%

https://www.codechef.com/problems/HS08TEST

Why am I getting a wrong answer?

include<iostream>

include<iomanip>

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"; }

link

answered 12 Jun '16, 15:04

arnav_roy's gravatar image

1★arnav_roy
433
accept rate: 0%

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;

}

link

answered 05 Jul '16, 11:05

runjhun123's gravatar image

1★runjhun123
1
accept rate: 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&lt;n;i++)" {="" m="100000000;" if(a[i]="=48)" {="" for(j="0;j&lt;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

link

answered 06 Jul '16, 02:13

tiwari9's gravatar image

2★tiwari9
1
accept rate: 0%

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

link

answered 04 Aug '16, 21:48

ekjot_kaur's gravatar image

1★ekjot_kaur
1
accept rate: 0%

include<iostream>

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?

link

answered 21 Aug '16, 10:43

krishnakk789's gravatar image

0★krishnakk789
1
accept rate: 0%

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

link

answered 21 Aug '16, 12:18

kama7's gravatar image

3★kama7
1
accept rate: 0%

why i get wrong answer

link

answered 02 Sep '16, 12:50

champrg's gravatar image

1★champrg
1
accept rate: 0%

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

link

answered 07 Sep '16, 01:37

shuvajit's gravatar image

0★shuvajit
1
accept rate: 0%

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 ?

link

answered 13 Sep '16, 19:52

vddesai's gravatar image

0★vddesai
1
accept rate: 0%

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.

link

answered 22 Sep '16, 09:30

upreti_bhawna's gravatar image

0★upreti_bhawna
1
accept rate: 0%

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 <iostream>

include <vector>

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;

}

link

answered 20 Oct '16, 09:40

kiamottullah's gravatar image

0★kiamottullah
1
accept rate: 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..

link

answered 20 Oct '16, 10:37

bansal1232's gravatar image

5★bansal1232
2.8k1419
accept rate: 16%

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

include<iostream>

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&lt;e;i++)" {="" if(j="=n-1&amp;&amp;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;

}

link

answered 23 Oct '16, 15:06

gaurav_jain013's gravatar image

0★gaurav_jain013
1
accept rate: 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

link

answered 29 Oct '16, 15:48

vishal_703's gravatar image

1★vishal_703
1
accept rate: 0%

include <stdio.h>

include <stdlib.h>

char a[25]; int top=-1; void push(char symbol) {

a[++top]=symbol;

} char pop() {

char item;
item=a[top--];
return(item);

} int precd(char op) {

int r;
switch(op)
{

case'^':r=3; break;
case'*':
case'/':
case'%':r=2; break;
case'+':
case'-':
case'(':r=0; break;
case'#':r=-1;
 break;
}
return(r);

} void infix_postfix(char infix[],char postfix[]) {

int i,p=0;
char symbol,item;
push('#');
for(i=0;infix[i]!= '\0';i++)
{

    symbol=infix[i];
    switch(symbol)
    {

        case '(':push(symbol);
        break;
        case ')':item=pop();
         while(item!= '(')
        {

            postfix[p++]=item;
            item=pop();
        }
        break;
        case'+':
            case'-':
            case'*':
            case'/':
            case'%':
            while(precd(a[top])>=precd(symbol));
            {

                item=pop();
                postfix[p++]=item;
            }
            push(symbol);
            break;
            default  : postfix[p++]=symbol;
            break;
    }
}
while(top>0)
{

    item=pop();
    postfix[p++]=item;
}
postfix[p]= '\0';

} int main() { char infix[25],postfix[25];

printf("enter infix expression");
scanf("%s",infix);
infix_postfix(infix,postfix);
printf("\npostfix expression:%s\n\n\t",postfix);
return 0;

}

link
This answer is marked "community wiki".

answered 03 Dec '16, 17:00

shafiq77's gravatar image

0★shafiq77
1
accept rate: 0%

include <iostream>

using namespace std; int main() { long long int t,n1,n2,k,l; cin>>t; for (int i=0;i<t;i++) {="" cin="">>n1>>n2; k=n1; l=n2; while(n1 != n2) { if(n1>n2) n1-=n2; else n2-=n1; } cout<<n1<<" "<<(k*l)/n1<<endl; } return 0; }

can someone help me, trying to submit this code but getting wrong answer.Tried another questions many time still not getting it right.This code displays hcf and lcm of two given numbers. Is there any role of constraints provided? or some specific way to output the answer? i'm a beginner please help.

link

answered 14 Dec '16, 21:22

coder_cpp's gravatar image

0★coder_cpp
1
accept rate: 0%

u dont need to use long long int for it.try this code.it is similar to ur code

include <iostream>

using namespace std;

int main() { int t,n1,n2; cin>>t; while(t--){ cin>>n1>>n2; int x=n1,y=n2; while(x!=y){ if(x>y) x-=y; else y-=x; } cout<<x<<endl<<n1*n2/x<<endl; } return 0;

link

answered 14 Dec '16, 22:34

wolfshadow's gravatar image

1★wolfshadow
1
accept rate: 0%

I FORGOT A } AFTER THE RETURN 0;. ADD THAT ALSO

link

answered 14 Dec '16, 22:35

wolfshadow's gravatar image

1★wolfshadow
1
accept rate: 0%

HOPE IT WAS USEFUL..

(14 Dec '16, 22:36) wolfshadow1★

Hi, i allways get wrong answer in my codes, even tho im getting the correct answer in various tests.

can someone help me?

this is an example: (Using C)

include <stdio.h>

include <stdlib.h>

int main() { int maxA,maxB,i,n,A[10000],B[10000],C[10000],D[10000],sum_A=0,sum_B=0; scanf("%d",&n); for (i=0;i<n;i++) {="" scanf("%d",&a[i]);="" scanf("%d",&b[i]);="" c[i]="A[i]-B[i];" d[i]="B[i]-A[i];" sum_a+="A[i];" sum_b+="B[i];" maxa="C[i];" maxb="D[i];" }="" for="" (i="1;i&lt;n;i++)" {="" if="" (c[i]="">C[(i-1)] && C[i]>maxA) { maxA=C[i]; } else if (C[(i-1)]>C[i] && C[(i-1)]>maxA) { maxA=C[(i-1)]; } if (D[i]>D[(i-1)] && D[i]>maxB) { maxB=D[i];

}
    else if (D[(i-1)]>D[i] && D[(i-1)]>maxB)
         {
             maxB=D[(i-1)];
         }

}

if (maxA>maxB) { printf("%d %d \n",1,maxA); } else { printf("%d %d \n",2,maxB); } return 0; }

link

answered 01 Jan '17, 04:39

prengineer's gravatar image

0★prengineer
1
accept rate: 0%

Contest Code: Practice Problem code: NUMGAME2 My solution:

include <bits stdc++.h="">

define pd(x) printf("%d",x)

define sld(x) scanf("%ld",&x)

define plld(x) printf("%lld",x)

define slld(x) scanf("%lld",&x)

using namespace std; long long int t; int isprime (long long int); int main() { long long int n,x,k,q; slld(t); while(t--) { k=0; slld(n); q=n-1; while(q>=1) { if((q==1||isprime(q))&&(n-q)>0) { n-=q; k++; q=n; continue; } q--; } if(k%2==0) printf("ALICE\n"); else printf("BOB\n"); } return 0; } int isprime( long long int N) { if(N<2 || (!(N&1) && N!=2)) return 0; for(int i=3; i*i<=N; i+=2){ if(!(N%i)) return 0; } return 1; }

Plz help to debug my code.

link

answered 05 Jan '17, 14:45

virus_hck's gravatar image

3★virus_hck
1
accept rate: 0%

it show wrong ans of matrix transformation

link

answered 31 Jan '17, 23:47

gursimran6996's gravatar image

0★gursimran6996
1
accept rate: 0%

include <iostream>

using namespace std;

int main(){ int t=0,n=0,i=1,j=0,ans=1 ; cin >> t ; while(i<=t){ cin >> n ; for(j=n;j>=1;j--){ ans *=j ; } cout << ans << endl; ans = 1; i++ ; } return 0; }

THIS IS SHOWING WRONG ANSWER . WHAT IS THE PROBLEM?

link

answered 11 Feb '17, 18:12

eshan292's gravatar image

2★eshan292
333
accept rate: 0%

Plz give a link to the Q you are solving.

(11 Feb '17, 18:19) vijju123 ♦♦5★
link

answered 11 Feb '17, 18:32

eshan292's gravatar image

2★eshan292
333
accept rate: 0%

include <iostream>

using namespace std ;

int main(){ int i=1,ans,p1,p2,n,lead=0; cin >> n; while(i<=n){ cin >> p1 >> p2 ; lead = lead + p1-p2 ; i++ ; } if(lead>0){ cout << "1" << " " << lead << endl; } else{ ans= lead * (-1) ; cout << "2" << " " << ans << endl; } return 0; }

why is this giving wrong answer? the url for this problem is https://www.codechef.com/problems/TLG

link

answered 12 Feb '17, 21:37

eshan292's gravatar image

2★eshan292
333
accept rate: 0%

include <iostream>

using namespace std ;

int main(){ int i=1,ans,p1,p2,n,lead=0; cin >> n; while(i<=n){ cin >> p1 >> p2 ; lead = lead + p1-p2 ; i++ ; } if(lead>0){ cout << "1" << " " << lead << endl; } else{ ans= lead * (-1) ; cout << "2" << " " << ans << endl; } return 0; }

why am i getting wrong answer? https://www.codechef.com/problems/TLG

link

answered 12 Feb '17, 21:39

eshan292's gravatar image

2★eshan292
333
accept rate: 0%

i have some more doubts but i cant ask question due to insufficient karma points so please upvote me

(02 Apr '17, 22:52) eshan2922★

@eshan292

I think you misinterpreted the Q.

You have to find the MAXIMUM difference in scores, and the player with the lead wins.

In your case, "lead = lead + p1-p2 " is taking into account the previous lead/lead in previous round, while the example clearly showed this is not the case.

I advice, please give another attempt in understanding the Q, and if you're still facing problem, look at its solution here

link

answered 12 Feb '17, 22:01

vijju123's gravatar image

5★vijju123 ♦♦
15.5k12066
accept rate: 18%

edited 12 Feb '17, 22:03

Hi. I am using System.out.println in java to print my answer. Would it cause new line trouble, giving WA? All my answers seem correct with given test cases and few more that I generated by my self.

link

answered 19 Feb '17, 00:42

pyrocoder's gravatar image

0★pyrocoder
1
accept rate: 0%

include <iostream>

using namespace std;

int main() { int t,n,i=0,j=0,a,b,c=0,sum=0,d=0,ctr=0,e,temp ; cin >> t ; while(i<t){ cin="">> n ; int arr[n] ; j=0 ; while(j<n){ cin="">> arr[j] ; j++ ; } c=0 ; sum=0 ; while(c<n){ sum=sum+arr[c] ; c++ ; } for(e=0;e<1;e++){ if(sum!=n*((n+1)/2)){ cout << "no" << endl; temp=1 ; break ; } ctr=0 ; d=0; while(d<n-1){ if(arr[d]+1==arr[d+1]){ ctr+=1 ; } d++ ; } if(ctr==n-1){ cout << "no" << endl ; temp=1 ; break ; } for(b=0;b<n;b++){ for(a=1;a<n;a++){ if(arr[b]==arr[a] && b!=a){ cout << "no" << endl; temp=1; break ; } } if(temp==1){ break; }

    }
    }
    if(temp!=1){
        cout << "yes" << endl;
    }
    i++ ;
}
return 0;

} why am i getting wrong answer? https://www.codechef.com/problems/KOL16J/-->url for the problem

link

answered 22 Feb '17, 10:57

eshan292's gravatar image

2★eshan292
333
accept rate: 0%

i have some more doubts but i cant ask question due to insufficient karma points so please upvote me

(02 Apr '17, 22:52) eshan2922★

this is code of life,the universe and everything.

include<stdio.h>

int main() { int a;

while(1) { scanf("%d\n",&a); if(a==42) break; } return 0; }

link

answered 01 Mar '17, 20:27

crearex's gravatar image

0★crearex
1
accept rate: 0%

You are printing nothing dear. The Q asks you to print the number entered on a new line UNTIL 42 is entered. Add a print statement after break statement and it will be fine. :)

(01 Mar '17, 20:36) vijju123 ♦♦5★

Why is my program getting wrong answer?

import java.util.*;

class pattern { public static void main(String argsp[]){ int q; Scanner in=new Scanner(System.in); int a,b,j,c,d; q=in.nextInt(); for(int i=1;i<=q;i++){ a=in.nextInt(); b=in.nextInt(); if(a<1||b<1||a==b) System.out.println("No"); else if(a==(b+2)||a==(b-2)) System.out.println("Yes"); else { j=(a-1)/2; c=2j+1; d=2j+2; if((c==a&&d==b)||(c==b&&d==a)) System.out.println("Yes"); else System.out.println("No"); } } } }

link

answered 02 Apr '17, 16:00

ammar0's gravatar image

0★ammar0
1
accept rate: 0%

def remove_dot(this_list,value): while value in this_list: this_list.remove(value)

def check(list2): if(list2==[]): return "Valid" elif(list2[0]=='T' or list2[len(list2)-1]=='H'): return "Invalid" else : count=0 for i in range(0,len(list2)-1,2): if(list2[i] is 'H' and list2[i+1] is 'T'): count+=1 if((count*2) is len(list2)): return "Valid" else : return "Invalid"

R=int(input()) L=[] str=[] dot='.' ans=[] for i in range(0,R): L.append(int(input())) #for j in range(0,L[i]): value=input() list=[] list[:0]=value remove_dot(list,dot) ans.append(check(list)) for i in range(0,R): print(ans[i])

This is my python code i run in my machine it gives me right output but when i submit in SmackDown contest it tells wrong answer i am trying from 2 days

link

answered 24 May '17, 12:46

ronaksahu's gravatar image

1★ronaksahu
1
accept rate: 0%

beginners first problem answer is getting wrong...please tell me where am I wrong?

include<stdio.h>

include<string.h>

int main() { int i,j,t,s,m; scanf("%d",&t); for(i=0;i<t;i++) { s=0; m=0; char str[100]; scanf("%s",str); for(j=0;str[j]!='\0';j++) {if(str[j]=='s') s+=1; else if(str[j]=='m') m+=1; } for(j=0;j!=(strlen(str)-1);j++) { if(str[j]=='s'&&str[j+1]=='m') { s-=1; str[j]='a';} else if(str[j]=='m'&&str[j+1]=='s') { s-=1; str[j+1]='a'; }

} if(m>s) printf("mongooses\n"); else if(s>m) printf("snakes\n"); else printf("tie\n");

} return 0; }

link

answered 02 Jun '17, 21:57

nsb94's gravatar image

0★nsb94
1
accept rate: 0%

https://discuss.codechef.com/questions/7640/why-do-i-get-wrong-answer/64059 there are a lot more cases which are hidden and sample cases are not the only ones otherwise there would be no point in submitting you could check them yourself right !!

link

answered 02 Jun '17, 22:54

soheb17's gravatar image

5★soheb17
602
accept rate: 0%

there are a lot more cases which are hidden and sample cases are not the only ones otherwise there would be no point in submitting you could check them yourself right !!

(02 Jun '17, 22:53) soheb175★
  1. Nick is now a well settled person. Impressed by the coding skills of Nick, N girls wish to marry him. Nick will consider marriage proposals of only those girls who have some special qualities. Qualities are represented by positive non-zero integers. Nick has a list of M qualities which he wants in a girl. He can also consider those girls who have some extra qualities, provided they have at least all those qualities which Nick wants. Find how many girls' proposal will Nick consider. Input: First line contains the integer M, denoting the number of qualities which Nick wants. Next line contains M single space separated distinct integers. Third line contains an integer N, denoting the number of girls. Next follow N lines, ith line contains few single-space separated distinct integers, denoting the qualities of the ith girl. Output: Print the number of girls, whose proposals will be considered by Nick. Constraints: 1 ≤ M ≤ 100 1 ≤ N ≤ 9 x 103 1 ≤ Maximum no. of qualities possessed by girls ≤ 1000. Qualities are positive non-zero integers such that 1 ≤ Quality ≤ 104 Subtask 1: ( 30 points ) 1 ≤ M ≤ 10 1 ≤ N ≤ 100 1 ≤ Maximum no. of qualities possessed by girls ≤ 100. Qualities are positive non-zero integers such that 1 ≤ Quality ≤ 1000 Subtask 2: ( 70 points ) Original constraints Sample Input: 5 1 2 3 4 5 3 1 2 3 4 5 6 1 2 3 4 5 1 2 3 4 Sample Output: 2

can any one ans me?

link

answered 05 Sep '17, 23:42

mohini1992's gravatar image

0★mohini1992
1
accept rate: 0%

  1. Nick is now a well settled person. Impressed by the coding skills of Nick, N girls wish to marry him. Nick will consider marriage proposals of only those girls who have some special qualities. Qualities are represented by positive non-zero integers. Nick has a list of M qualities which he wants in a girl. He can also consider those girls who have some extra qualities, provided they have at least all those qualities which Nick wants. Find how many girls' proposal will Nick consider. Input: First line contains the integer M, denoting the number of qualities which Nick wants. Next line contains M single space separated distinct integers. Third line contains an integer N, denoting the number of girls. Next follow N lines, ith line contains few single-space separated distinct integers, denoting the qualities of the ith girl. Output: Print the number of girls, whose proposals will be considered by Nick. Constraints: 1 ≤ M ≤ 100 1 ≤ N ≤ 9 x 103 1 ≤ Maximum no. of qualities possessed by girls ≤ 1000. Qualities are positive non-zero integers such that 1 ≤ Quality ≤ 104 Subtask 1: ( 30 points ) 1 ≤ M ≤ 10 1 ≤ N ≤ 100 1 ≤ Maximum no. of qualities possessed by girls ≤ 100. Qualities are positive non-zero integers such that 1 ≤ Quality ≤ 1000 Subtask 2: ( 70 points ) Original constraints Sample Input: 5 1 2 3 4 5 3 1 2 3 4 5 6 1 2 3 4 5 1 2 3 4 Sample Output: 2

can any one ans me?

link

answered 05 Sep '17, 23:42

mohini1992's gravatar image

0★mohini1992
1
accept rate: 0%

  1. Nick is now a well settled person. Impressed by the coding skills of Nick, N girls wish to marry him. Nick will consider marriage proposals of only those girls who have some special qualities. Qualities are represented by positive non-zero integers. Nick has a list of M qualities which he wants in a girl. He can also consider those girls who have some extra qualities, provided they have at least all those qualities which Nick wants. Find how many girls' proposal will Nick consider. Input: First line contains the integer M, denoting the number of qualities which Nick wants. Next line contains M single space separated distinct integers. Third line contains an integer N, denoting the number of girls. Next follow N lines, ith line contains few single-space separated distinct integers, denoting the qualities of the ith girl. Output: Print the number of girls, whose proposals will be considered by Nick. Constraints: 1 ≤ M ≤ 100 1 ≤ N ≤ 9 x 103 1 ≤ Maximum no. of qualities possessed by girls ≤ 1000. Qualities are positive non-zero integers such that 1 ≤ Quality ≤ 104 Subtask 1: ( 30 points ) 1 ≤ M ≤ 10 1 ≤ N ≤ 100 1 ≤ Maximum no. of qualities possessed by girls ≤ 100. Qualities are positive non-zero integers such that 1 ≤ Quality ≤ 1000 Subtask 2: ( 70 points ) Original constraints Sample Input: 5 1 2 3 4 5 3 1 2 3 4 5 6 1 2 3 4 5 1 2 3 4 Sample Output: 2

can any one ans me?

link

answered 05 Sep '17, 23:42

mohini1992's gravatar image

0★mohini1992
1
accept rate: 0%

This is my code https://www.codechef.com/viewsolution/15941757

for https://www.codechef.com/problems/MARCHA1 this.

In CodeChef IDE My code run properly and give the right output for the given inputs. but at the submission time it show me WRONG ANSWER!!! message.

What is problem with my Code???

link

answered 23 Oct '17, 10:57

begentleman's gravatar image

1★begentleman
1
accept rate: 0%

import java.util.Scanner; public class A1 { public static void main(String args[]){ Scanner input=new Scanner(System.in); int t=input.nextInt(); int a[]=new int[t]; for(int i=0;i<t;i++) { System.out.println(""); int n=input.nextInt(); int factorial=1;
for(int x=1;x<=n;x++){ factorial=factorial*x; } a[i]=factorial; }

for(int d=0;d<t;d++){ System.out.println(a[d]); } } }

link

answered 13 Aug '18, 12:28

raianibnfaiz's gravatar image

0★raianibnfaiz
1
accept rate: 0%

For Practice Survive import java.util.; import java.lang.; import java.io.; / Name of the class has to be "Main" only if the class is public. / class Codechef { public static void main (String[] args) throws java.lang.Exception { Scanner sx=new Scanner(System.in); int t=sx.nextInt(); if(t<=100) { for(int i=0;i<t;i++) { int n=sx.nextInt(); int k=sx.nextInt(); int s=sx.nextInt(); if(n<=100 && k<=100 && s<=1000) { int res=(n(s-(s/7)))-ks; if(res<0) { System.out.println("-1"); } else if(res==0) { System.out.println(s-(s/7)); }else{System.out.println(1+((ks)/n));}}}}sx.close();}}

link
This answer is marked "community wiki".

answered 14 Aug '18, 23:24

dakshjn994's gravatar image

0★dakshjn994
1
accept rate: 0%

include<iostream>

using namespace std; int main() { long int n,m,diff; cin>>n>>m; diff=n-m; cout<<endl;

if(diff>=0)
{

if((diff%2)==0)
{
    diff+=1;
}
else
{
    diff-=1;
}
cout<<diff;

} else return 0; } whats the prblem in above code???

link

answered 19 Sep '18, 00:13

sidlasure's gravatar image

0★sidlasure
1
accept rate: 0%

include <bits stdc++.h="">

using namespace std;

bool mem[122][1000002]; bool gop = false; int N; vector<int> ps; vector<int> ans; void dfs(int dx, int sam, int bef, string ss) { if (sam + bef > N || gop) { return; } if (sam + bef == N && dx>=ss.length()) { for (auto v : ps) { ans.push_back(v); } gop = true; return; } if (mem[dx][sam + bef] != 0) { return; } if (sam + bef > 0) { mem[dx][bef + sam] = 1; } if (dx >= ss.length()) { return; } int nev = 0; for (int i = dx;i < dx + 7 && i<ss.length();i++) {="" nev="nev" *="" (int)10="" +="" (int)(ss[i]="" -="" '0');="" if="" (nev=""> N) { return; } ps.push_back(dx); dfs(i + 1, sam + bef, nev, ss); ps.pop_back(); } }

int main() { int test;cin >> test; while (test--) { gop = false;ps.clear();ans.clear(); memset(mem, false, sizeof mem); string ss;cin >> ss; cin >> N; dfs(0, 0, 0, ss); string rol;rol.resize(ans.size() - 1 + ss.length()); reverse(ans.begin(), ans.end()); ans.pop_back(); reverse(ans.begin(), ans.end()); for (int z = 0, j = 0, k = 0;z < rol.length();z++) { if (j < ss.length() && (k >= ans.size() || j < ans[k])) { rol[z] = ss[j]; j++; } else if (k < ans.size()) { rol[z] = '+'; k++; } } cout << rol << endl; } return 0; }

link

answered 23 Sep '18, 00:59

badshah143's gravatar image

0★badshah143
1
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×1,070
×214

question asked: 22 Mar '13, 16:31

question was seen: 45,500 times

last updated: 23 Sep '18, 00:59