Why do I get Wrong Answer?

,

#include

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?
CodeChef: Practical coding for everyone>url for the problem

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

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=2
j+2;
if((c==a&&d==b)||(c==b&&d==a))
System.out.println(“Yes”);
else
System.out.println(“No”);
}
}
}
}

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

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

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

  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?

  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?

  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?

This is my code CodeChef: Practical coding for everyone

for MARCHA1 Problem - CodeChef 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???

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

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+((k
s)/n));}}}}sx.close();}}

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

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

bool mem[122][1000002];
bool gop = false;
int N;
vector ps;
vector 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;
}

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

1 Like

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

1 Like

why is it showing wrong answer?

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

HOPE IT WAS USEFUL…

Plz give a link to the Q you are solving.