When I submit my code for a particular problem on CodeChef, who will test if my solution is correct or not? Can some one tell me how is my solution tested?
Your code is tested by a computer automatically, not by a human being, and you have to write your code accordingly.
For each problem, Codechef will have one or more input files, each according to the specifications mentioned in the problem statement, and corresponding correct output files. Codechef will run your program on each of the input files by redirecting the standard input stream to an input file, and the standard output stream to another file. The output generated by your program must match the correct output exactly in order to be judged correct.
Some consequences of this:
-
If your program starts by printing ‘Enter the number’ and the problem does not tell you to do so, then since this is not part of the correct output, you will be never be judged correct regardless of what the rest of your program does.
-
As all that matters is that the output files match, it makes no difference at all at what point in your program’s execution that this output is written. So there is no need to read all of the input before starting output; it is much more common to just print out each result as you are reading through the input.
-
If you use any method other than using the standard input and output streams - for example, using command line arguments, reading from a file, opening up some sort of dialog box, or otherwise - you will never be judged correct.
#include<stdio.h>
#include<math.h>
long long int prime(long long int );
long long int sum_factor(long long int );
long long int prime_no(long long int p)
{
long long int h;
for(h=2;h<p;h++)
{
if(p%h==0)
{
break;
}
}
if(h==p)
return§;
else
return(0);
}
int main()
{
long long int t,l,r,i,d,b;
scanf("%lld",&t);
while(t--)
{
long long int sum=0;
for(i=l;i<=r;i++)
{
b=2;
d=1;
do
{
d=pow(b,2);
if(i%d==0)
{
d=0;
break;
}
b=b+1;
}while(i>=d);
if(d==0)
continue;
else
{
sum+=sum_factor(i);
}
}
printf("%lld\n",sum);
}
return 0;
}
long long int prime(long long int a)
{
long long int s[a],y=0,k,m,c=0;
for(k=2;k<=a;k++)
{
m=prime_no(k);
if(m>0)
{
s[y]=m;
y++;
}
}
for(k=0;k<y;k++)
{
if(a%s[k]==0)
{
c++;
}
}
c=prime_no(c);
if(c>0)
return (a);
else
return (0);
}
long long int sum_factor(long long int x)
{
long long int sm,j,res;
sm=0;
for(j=1;j<=x;j++)
{
if(x%j==0)
{
sm+=j;
}
}
res=prime(sm);
return (res);
}
#include <stdio.h>
int main()
{
int t,i,n,p,r,c;
scanf("%d\n",&t);
for(i=0;i<t;i++)
{
scanf("%d\n",&n);
p=0;
c=0;
while(n!=0)
{
r=n%10;
c++;
if(r==0)
p++;
n=n/10;
}
if((p==1) || (p==c-1))
printf(“yes\n”);
else
printf(“no\n”);
}
return 0;
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.Arrays;
class UncleJohny {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N;
int t = br.read();
br.readLine();
for (int i = 0; i < t; i++) {
N = Integer.parseInt(br.readLine());
String s1 = br.readLine();
String s[] = s1.split(" ");
int a[] = new int[N];
for (int j = 0; j < N; j++) {
a[j] = Integer.parseInt(s[j]);
}
int K = Integer.parseInt(br.readLine());
int c = a[K - 1];
Arrays.sort(a);
for (int m = 0; m < N; m++) {
if (a[m] == c) {
System.out.println(m + 1);
break;
}
}
}
}
}
#include<stdio.h>
int main()
{
int c,d,l,i=0,j=0,k,f=0,t,p;
int x[100000];
scanf("%d",&t);
for(p=0;p<t;p++)
{
i=0,f=0,j=0;
scanf("%d%d%d",&c,&d,&l);
if(c<=d)
k=c+1;
if(c>d)
k=2d;
while(i<k)
{
if((4c+4*d)-j==l)
{
f=1;
break;
}
i++;
j=j+4;
}
if(f==1)
x[p]=f;
else
x[p]=f;
}
for(p=0;p<t;p++)
{
if(x[p]==1)
puts(“yes”);
else
puts(“no”);
}
return 0;
}
#include<stdio.h>
#include<malloc.h>
int gcd(int ,int );
int main(void)
{
int i=0,t,j=0,n,sum=0,flag=1,z=0;
int *a,*result;
do{
scanf("%d",&t);
if(t>=1 && t<=200000)
{
flag=0;
}
}while(flag);
z=t;
while(t--)
{
flag=1;
do{
scanf("%d",&n);
if(n>=1 && n<=1000000)
{
flag=0;
}
}while(flag);
sum=0;
a=(int *)malloc(n*sizeof(n));
result=(int *)malloc(t*sizeof(int));
for(i=1;i<=n;i++)
{
for(j=i+1;j<=n;j++)
{
sum=sum+gcd(a[i],a[j]);
}
}
result[t]=sum;
}
for(i=z;i>=1;i--)
{ printf("%d",result[i]); }
return 0;
}
int gcd(int a,int b)
{
int r;
do{
r=a%b;
a=b;
b=r;
}while(r!=0);
return a;
}
#include <bits/stdc++.h>
using namespace std;
void te() {
int n;
cin >> n;
vector s(n);
for(int i = 0; i < n; ++i)
cin >> s[i];
for(int i = 0; i < n; ++i)
if(s[i] == “cookie”)
if(i == n - 1 || s[i+1] == “cookie”) {
puts(“NO”);
return;
}
puts(“YES”);
}
int main() {
int T;
cin >> T;
while(T–) te();
}
#include<stdio.h>
#include<math.h>
int main()
{
unsigned long int n,count,s,a=0,k;
scanf("%lu %lu",&n,&k);
if(n<=pow(10,7)&&k<=pow(10,7))
{
while(a<n)
{
scanf("%ld",&s);
if(s<=pow(10,9)&&s%k==0)
{
count++;
}
a++;
}
}
printf("%lu",count);
return 0;
}
How do i get input and write output in PHP?
I run code in IDE, it take 0,01s. But when i submit the code, i get “Time limit exceeded”.
Your code is correct or not is determined by test case writtern by problem setter or experienced competitive coder and reviewed by various other coder.
When you submit your solution it feed specific input sets and test your output against its correct output files. Its all done in milliseconds by machine :);
import java.util.Scanner;
class SF{
public static void main (String[] arts){
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int a[]=new int[n];
int b[]=new int[n];
for(int i=0;i<n;i++)
{
a[i]=s.nextInt();
int f=1;
for(int j=1;j<=a[i];j++)
{
f=f*j;
}
b[i]=f;
}
for(int i=0;i<n;i++)
{System.out.println(b[i]);}}}
import math
T=int(input())
for i in range(T):
N=int(input())
a=int(math.log2(N))
b=2a
if N==2:
print(1)
elif N==1:
print(2)
elif b==N:
print(1)
else:
c=N-b
d=int(math.log2©)
print(min(c-2d,2**(d+1)-c))
what is wrong in this code
hii
Do you send snack down code plese
#include <stdio.h>
int main() {
int T;
char name[100];
int count ,count1,i;
scanf("%d",&T);
for(i=0;i<T;i++)
{
scanf(" ");
gets(name);
for(int j=0;name[j]!='\0';j++)
{
if(name[j]=='R')
{
count1++;
}
else
{
count++;
}
}
if(count1==count)
{
printf("yes\n");
}
else
{
printf("no");
}
count=0;
count1=0;
}
return 0;
}
I do not know who wrote it here (and I can’t find it now), that tester ignores empty lines, is it correct?
Any amount of whitespace is considered equivalent to any other amount of whitespace. If you are asked to print one space between answers, and print three returns, 2 spaces, 4 tabs, and a few extra \r characters, that makes no difference.
how should i know why my submission is wrong? how can i find where it is wrong?
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class skdhj
{
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N;
int t = br.read();
br.readLine();
for (int i = 0; i < t; i++) {
N = Integer.parseInt(br.readLine());
String s1 = br.readLine();
String s[] = s1.split(" ");
int a[] = new int[N];
for (int j = 0; j < N; j++) {
a[j] = Integer.parseInt(s[j]);
}
int K = Integer.parseInt(br.readLine());
int c = a[K - 1];
Arrays.sort(a);
for (int m = 0; m < N; m++) {
if (a[m] == c) {
System.out.println(m + 1);
break;
}
}
}
}
}