CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • May Cook-Off 2013
    • May Challenge 2013
    • April Cook-Off 2013
    • April Challenge 2013
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • Campus Chapters
    • Host your Contest
    • Go for Gold
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
    • Top Contributors on Discuss
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Practice(easy) » Life, the Universe, and Everything

Life, the Universe, and Everything

Problem code: TEST

  • Submit
  • All Submissions

All submissions for this problem are available.

For help on this problem, please check out our tutorial Input and Output (I/O)


Your program is to use the brute-force approach in order to find the Answer to Life, the Universe, and Everything. More precisely... rewrite small numbers from input to output. Stop processing input after reading in the number 42. All numbers at input are integers of one or two digits.

Example


Input:
1
2
88
42
99

Output:
1
2
88

Author: admin
Date Added: 23-02-2009
Time Limit: 3 sec
Source Limit: 50000 Bytes
Languages: ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC


  • Submit

Comments

  • Login or Register to post a comment.

where should i type the

rajarameshh @ 24 Nov 2010 12:24 PM

where should i type the code

is notepad ok?

time limit exceeded error for

rohanpkumbhar @ 27 Nov 2010 08:38 PM

time limit exceeded error for following code......plz help me reduce time consumption

#include<stdio.h>

int main(void)

{

unsigned int num;

for(;printf("%d",scanf("%d",&num)!=42););

return(0);

}

Your program never exits.

triplem @ 28 Nov 2010 02:09 AM

Your program never exits. Your scanf function will never return 42.

why this doesn't get accepted

piergiu @ 2 Dec 2010 10:58 PM

why this doesn't get accepted ?

 

 

#include <stdio.h>

 

int main(){

int num=0;

for(;num!=42;printf("%dn", num,scanf("%d", &num)));

return 0;

}

 

It gives the wrong answer for

triplem @ 3 Dec 2010 01:43 AM

It gives the wrong answer for every single input, including the sample input.

Why '\'(backslash) not coming

codephodu @ 4 Dec 2010 02:35 AM

Why ''(backslash) not coming before n in my code?

Is there any technical problem?

The problem is that you

triplem @ 4 Dec 2010 02:37 AM

The problem is that you aren't meant to post code in comments, which you would know if you had read the FAQ. You will also find the solution to your problem there.

Actually I have doubt with

balascjp @ 7 Dec 2010 08:28 PM

Actually I have doubt with question

After entering all input values the output can listed out (ie) get all values if 42 appears then it print all other values....

eg:

10

20

30

42

o/p 10 20 30

or

if enter one value and it gives output until enter 42

10

10

65

65

42

---->ends

Read the FAQ.

triplem @ 8 Dec 2010 01:36 AM

Read the FAQ.

*snip* what is difference b/w

lavish_goel @ 16 Dec 2010 08:40 PM

*snip*

what is difference b/w lower code and upper code.....????

lower is correct...

and in upper code case..it prints wrong answer

The upper code starts by

triplem @ 17 Dec 2010 01:37 AM

The upper code starts by printing out "How Many values do you want to input". That is not part of the correct solution, so you get wrong answer. Please read the FAQ.

Why do you insist on posting

mrhota @ 22 Dec 2010 03:41 AM

Why do you insist on posting your code in the comments?

Do you not understand what this site is supposed to be about?

How do we accept input for

umang_rungta @ 23 Dec 2010 09:03 PM

How do we accept input for C++??

Will cin work, or we have to input from file?

I just wrote the solution of

harsh_kumar @ 26 Dec 2010 05:12 PM

I just wrote the solution of this problem in C# and there what was astonishing that i just input, compare and display till 42 is entered.

Time: 0.19 secs

Mem: 11.2M

A lot of solutions in C / C++ does almost the same, but they have a better Time and Memory performance. Is it normal for C# to take more memory and time ?

I am very new to this forum,

manas2lucky @ 29 Dec 2010 11:16 PM

I am very new to this forum, I wrote this program as the practice, but it gave me runtime error. Could you let me know, what I need to do?

Thanks

You could start by reading

triplem @ 30 Dec 2010 02:13 AM

You could start by reading the FAQ.

please if anyone can tell me

vibhavsingh @ 5 Jan 2011 04:31 PM

please if anyone can tell me why d codechef compiler is telling  "wrong answer" of this solution..........

need assistance...

d program is giving required output on my cmd.........

You aren't meant to output

triplem @ 6 Jan 2011 02:32 AM

You aren't meant to output the word 'output'. You also shouldn't assume there are only 50000 numbers in the input, but you might get lucky and get accepted anyway.

i have also verified Through

manish_ranjan @ 8 Jan 2011 03:53 PM

i have also verified Through FAQ i am getting Run Time (Other) i checked with un used variables There arent any :) And memory also i havent declared more than necessary

Please Help

@aweety:dont know the error

eagleye @ 8 Jan 2011 11:47 PM

@aweety:dont know the error bt dont use printf("enter the number")  line it will give error on codechef compiler

@sweety:dont know the error

eagleye @ 8 Jan 2011 11:47 PM

@sweety:dont know the error bt dont use printf("enter the number")  line it will give error on codechef compiler

Getting Run Time error

manish_ranjan @ 9 Jan 2011 09:44 AM

Getting Run Time error :(:(

Can some body help please ??

I am able to Execyte perfectly on my Ecllipse

 

import java.util.Scanner;

public class Main {

public static void main (String args[])

{

int i=1;

int []anArray;

anArray = new int[100];

while (true)

{

Scanner scanner = new Scanner(System.in);

anArray[i] = scanner.nextInt();

if((anArray[i])==42)

{

break;

}

//     System.out.print("n In loop"+i+"n");

i++;

}

//     System.out.print("n After coming out of loop "+i+"n");

for (int pos=1;pos<i;pos++)

{

System.out.println(anArray[pos]);

//     System.out.print("n Printing the value of Pos:"+pos+"n");

}  

}

}

Please read the FAQ (in

triplem @ 9 Jan 2011 10:55 AM

Please read the FAQ (in particular, 'other common mistakes'; same applies to Scanners).

Hi Stephen i changed the

manish_ranjan @ 9 Jan 2011 01:38 PM

Hi Stephen

i changed the Scanner  and taking input from Buffers Stream ,, It still shows Run Time error

I debugged it and i think i have made sure that its not doint any thng what is mentioned in

FAQ ..

Please Help pasting the modified code

 

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

public class Main {

public static void main (String args[])

{

int i=0;

int []anArray;

String line=null;

anArray = new int[100];

while (true)

{

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

try {

line=br.readLine();

anArray[i] = Integer.parseInt(line);

System.out.print("n In loop value Stored"+anArray[i]+"n");

} catch (IOException e) {

e.printStackTrace();

}

if((anArray[i])==42)

{

break;

}

System.out.print("n In loop"+i+"n");

i++;

}

//     System.out.print("n After coming out of loop "+i+"n");

for (int pos=0;pos<i;pos++)

{

System.out.println(anArray[pos]);

}  

}

}

You didn't read the bit I

triplem @ 9 Jan 2011 02:30 PM

You didn't read the bit I mentioned. The point is whatever you use, you should only create one such object on the standard input stream, not once every loop.

#include<stdio.h>   int

jaipurchamp_1 @ 10 Jan 2011 03:42 PM

#include<stdio.h>

 

int main()

{

int t;

while(1)

{

scanf("%d",&t);

if(t==42||t>99)

break;

printf("%d",t);

}

return 0;

}

 

Its Showing correct Output on my PC

using System; class

anurag_patil @ 10 Jan 2011 09:53 PM

using System;
class Life_Universe_and_Everything
{
static void Main(string[] args)
{
int n=1, a;
Console.Write("How many numbers do you want to enter ?");
n = int.Parse(Console.ReadLine());
int[] array1 = new int[n];
for (int i = 0; i < n; i++)
{
a = int.Parse(Console.ReadLine());
if (a < 100)
array1[i] = a;
else
{
Console.WriteLine("Enter Only 1 or 2 Digit numbers");
i--;
}
}
for (int i = 0; i < n; i++)
{
if (array1[i] != 42)
Console.WriteLine(array1[i]);
else
i = n;
}
}
}

public class Main{    private

abhishek_oza @ 11 Jan 2011 06:09 PM

public class Main
{    private static int readInt() throws Exception
{    int i=0;
int r=0;
//while((i=System.in.read())!='n'&&i!='r');
while((i=System.in.read())!='n'&&i!='r')
{    r*=10;
r+=(i-'0');
}
return r;
}
public static void main(String[]arg)throws Exception
{    for(int i=0;(i=readInt())!=42;
System.out.println(i));
}
}

Why does this give a runtime

mihirk @ 12 Jan 2011 01:07 PM

Why does this give a runtime error?

It runs correctly on my ubuntu 8.04 machine.

 

#include<stdio.h>
#include<stdlib.h>

int main() {
int i;
while(1) {
scanf("%d", &i);
if(i != 42)
printf("%dn", i);
else
exit(1);
}

}

Do you know what the exit

triplem @ 12 Jan 2011 02:56 PM

Do you know what the exit function does? I suggest you read some C documentation on it, and/or read the FAQ.

//hello what is wrong with my

zun1989 @ 14 Jan 2011 07:41 PM

//hello what is wrong with my code please help, they are giving compile error.

 

 

 

 

 

import java.util.Scanner;


public class Bruteforce {




public static void main(String[] args) {

Scanner input = new Scanner(System.in);



int i;

for(;;){
System.out.print("enter int number : n");

i=input.nextInt();
System.out.printf(" %d ", i );

if(i==42){
break;}
}
}

#include<iostream.h> #include

brightstar @ 16 Jan 2011 01:08 PM

#include<iostream.h>

#include<conio.h>

void main()

{

int a[25],n;

cout<<"n Enter the no. of elements u want to enter:";

cin>>n;

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

cin>>a[i];

i=0;

while(a[i]!=42)

{

cout<<a[i];

i++;

}

getch();

}

@Ritika: I fear the solution

rajneesh2k10 @ 17 Jan 2011 11:58 AM

@Ritika:

I fear the solution is completely wrong!

You need to read the FAQ!

import

prophesy @ 17 Jan 2011 07:56 PM

import java.util.Scanner;

 

public class BrutForce

{

public static void main(String... args)

{

Scanner input = new Scanner(System.in);

int number = 0;

while(true)

{

number = input,nextInt();

if (number == 42)  break;

System.out.println(number);

}

}

}

#include<stdio.h> #include<co

lucky_cool_39 @ 17 Jan 2011 11:51 PM

#include<stdio.h>

#include<conio.h>

#define pf printf

#define sf scanf

void main()

{

int a,i,n;

clrscr();

pf("nn PLZ enter how many times u want to keep entering the value n");

sf("%d",&a);

for(i=1;i<=a;i++)

{

pf("nenter the value but beware do not enter the value 42 or the program will terminatenn");

sf("%d",&n);

if(n==42)

{

pf("caution !!!! u have entered 42 as valuennnt the program will now terminatennpress any                                                                                                                               key to continuen");

ghetch();

break;

}

pf("nnthe entered value is ===> %dnn",n);

}// end of for

} // end of main

@Nilesh: Please read FAQ!

rajneesh2k10 @ 18 Jan 2011 01:44 PM

@Nilesh:

Please read FAQ!

help me with this IN C if i

tj91 @ 19 Jan 2011 11:01 PM

help me with this IN C

if i use linkd list,time limit exceeds

if i use array i have to give array sze constant

Don't use either. Print each

triplem @ 20 Jan 2011 08:51 AM

Don't use either. Print each number as you read it. (See the FAQ if you don't know how your code is tested.)

public static void

zun1989 @ 21 Jan 2011 07:00 PM

public static void main(String[] args) {


Scanner input = new Scanner(System.in);



int i;



for(;;){
i=input.nextInt();
if(i!=42)
System.out.printf(" %d ", i );
else
break;
}

}



is this code ok?

#include<stdio.h>int

suni619 @ 23 Jan 2011 02:50 PM

#include<stdio.h>
int main()
{
int t;
while(1)
{
scanf("%d",&t);
if(t==42)break;
printf("%dn",t);
}
return 0;
}

#include<stdio.h>void main(){

lovelysurendar @ 26 Jan 2011 07:28 PM

#include<stdio.h>
void main()
{
int i,j,temp,c[99],a[99],b,d;
clrscr();
printf("Enter the no of inputs");
scanf("%d",&b);
printf("Enter the no one by one");
for(i=0;i<b;i++)
{
//printf("n");
scanf("%d",&a[i]);
}
for(i=0;i<b;i++)
{
if(a[i]!=42)
{
c[i]=a[i];
//printf("%d",a);
}
else
{
d=i;
break;
}
}
for(i=0;i<d;i++)
{
for(j=0;i<d;j++)
{
if(c[j]>c[i])
{
temp=c[j];
c[j]=c[i];
c[i]=temp;
}
}
}
for(i=0;i<d;i++)
printf("%dt",c[i]);
getch();
}

 

 

This program is running in my turbo c compiler but i cant submit can u help me please

#include <stdio.h>#include

lovelysurendar @ 27 Jan 2011 06:58 PM

#include <stdio.h>
#include <string.h>
int main()
{
int num[99];
int i,j,temp,a[99];
i=0;
while(scanf("%d",&num[i]))
{
if(num[i]!=42)
{
a[i]=num[i];
d=i;
i++;
}
else
{
break;
}
}
for(i=0;i<d;i++)
{
for(j=0;j<d;j++)
{
if(a[j]>a[i])
{
temp=a[j];
a[j]=a[i];
a[i]=temp;
}
}
}
return 0;
}

what wrong in this program Please anyone help me

while submitting it giving the error wrong answer

#include<stdio.h> int

pulkitbnsl @ 28 Jan 2011 11:47 PM

#include<stdio.h>

int main()

{

int x;

for(;;)

{

scanf("%d",&x);

if(x>0&&x<100&&x!=42)

printf("%dn",x);

else

break;

}

return 0;

}

why the above code is being rejected?

#include "stdio.h"   int

mohan1kumar91 @ 30 Jan 2011 12:21 AM

#include "stdio.h"

 

int main(){

int i;

for(;;){

scanf("%d", &i);

 

if(i != 42){

printf("%dn", i);

} else {

return 0;

}

}

}

#include<stdio.h> void

anubha @ 1 Feb 2011 07:15 PM

#include<stdio.h>

void main()

{

int arr[5],i;

printf("enter five intergersn");

for(i=0;i<5;i++)

{

scanf("%d",&arr[i]);

}

for(i=0;i<5;i++)

{

if(arr[i]==42)

break;

else

printf("%dn",arr[i]);

}

getch():

}

 

can someone please suggest what's wrong with my ans.

#include<stdio.h> int

anushkagarg @ 1 Feb 2011 07:51 PM

#include<stdio.h>

int main()

{

int a;

while(1)

{

scanf("%d",&a);

if(a==42)break;

printf("%dn",a);

}

return 0;

}

Okay, I uploaded my .java

dcanthill77 @ 3 Feb 2011 11:39 AM

Okay, I uploaded my .java file and it told me that there were compile errors! I know that is not true because I compiled the program and ran it several times before I uploaded the file to your site.

 

I'm using JGrasp to write and compile my Java programs...is that the problem? Do I need to use some other method in order to have a successful upload??

I presume you've read the

triplem @ 3 Feb 2011 11:52 AM

I presume you've read the FAQ?

Yes, I've read through the

dcanthill77 @ 3 Feb 2011 08:04 PM

Yes, I've read through the FAQ but I'm a beginner programmer and the details of the FAQ are vague to me. I can't seem to figure out how your computer compiles the programs. I think I should just drop out of this until I've had a few years of programming experience. Although I was able to successfully get my program to function properly for a user, I am not able to figure out your compiling system...

Vague? It seems pretty

triplem @ 4 Feb 2011 01:32 AM

Vague? It seems pretty specific. For example, under the 'Why do I get a compile error' section, it tells you your java class must be called Main. Yours isn't. It also tells you under the first section that you shouldn't be prompting the user for input in a dialog box, and in the second section how to test your code properly.

This is my java code. /* *

shahensha @ 7 Feb 2011 08:51 PM

This is my java code.

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

package codechef;

 

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

 

/**

*

* @author admin

*/

public class Main {

 

/**

* @param args the command line arguments

*/

public static void main(String[] args) throws IOException {

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

int input = Integer.parseInt(br.readLine());

while (input != 42) {

System.out.println(input);

input = Integer.parseInt(br.readLine());

}

}

}

But the system isn't accepting it, although it works fine on my computer. Can somebody please enlighhten me?

class Life{public static void

mayurpatidar @ 7 Feb 2011 10:56 PM

class Life{
public static void main(String ar[])
 {

//command line argument for input

 for(int i=0;i<ar.length;i++)
  {
   if(Integer.parseInt(ar[i])==42)
   break;
   System.out.println(ar[i]);
  }

 }
}

admin i posted this following

mitakshgupta @ 16 Feb 2011 11:17 PM

admin i posted this following program as the solution to this problem.. it is working fine on my compiler but it is showing a run time error here.. can you please tell where the error is?

#include<stdio.h>
void main()
{
int num;
while(1)
{
scanf("%d",&num);
if(num==42)
break;
else
printf("n%d",num);
}
}

admin i submitted this code

mitakshgupta @ 16 Feb 2011 11:46 PM

admin i submitted this code of mine as  a solution to this problem but it is showing some run time error n it is working fine on my compiler... kindly check where the problem actually exists..

#include<stdio.h>
void main()
{
int num;
while(1)
{
scanf("%d",&num);
if(num==42)
break;
else
printf("n%d",num);
}
}

Please read the FAQ.

triplem @ 17 Feb 2011 12:14 PM

Please read the FAQ.

did it in first try...felt

shyguy1188 @ 18 Feb 2011 01:59 AM

did it in first try...felt great... awesome this night is of some worth today: :) time is 1:59 a.m.

i did it in first try.. felt

shyguy1188 @ 18 Feb 2011 02:01 AM

i did it in first try.. felt great.. :)

My program running fine on my

fluteofcoder @ 18 Feb 2011 06:37 PM

My program running fine on my compiler whats wrong here

#include<iostream>
using namespace std;
int main()
{
int i=0;
for(;(cin>>i)&&i!=42;cout<<i);
}

i done with this

fluteofcoder @ 18 Feb 2011 06:42 PM

i done with this problem.....

my question is how this program related with the life ,universe..blah blah

import

sitaramkola @ 18 Feb 2011 10:44 PM

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 *
 * @author ASP.NET
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int x = Integer.parseInt(br.readLine());
        if(x!=42)
            System.out.print(x);
    }

}

I am getting wrong answer in submission why???

Your program gives the wrong

triplem @ 19 Feb 2011 01:45 AM

Your program gives the wrong answer for the sample input. All it prints is 1.

#include<stdio.h> int

gunjan1801 @ 23 Feb 2011 10:34 PM

#include<stdio.h>

int main()

{

int a;

while(1)

{

printf("%d",a);

scanf("%d",&a);

if(a=42)

break;

}

}

i m beginner help me out

#include<stdio.h> #include<st

manasa530 @ 24 Feb 2011 10:08 AM

#include<stdio.h>

#include<stdlib.h>

int main()

{

int a,n,i;

printf("enter numbers that u are interested ")

scanf("%d",&n)

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

scanf("%d",&a[i]);

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

{

if(a[i]==42)

exit(0);

else

printf("%d",a[i]);

}

}

#include<stdio.h>main(){ int

cukin_frazzy @ 26 Feb 2011 02:44 PM

#include<stdio.h>
main()
{
int a,b;
b=1;
while(b=1)
{   
printf("please enter the no.");
scanf("%d",&a);

if (a!=42)
{printf("tt%d",a);
}
else{
b=0;
break;
}
}
return 0;

}

#include<iostream.h> #include

subha @ 26 Feb 2011 09:59 PM

#include<iostream.h>

#include<conio.h>

void main()

{

int a,b[100],p=0;

while(1)

{

cin>>a;

if(a==42)

break;

{

b[p]=a;

p++;

}

}

for(int c=0;c<p;c++)

cout<<b[c];

getch();

}

what's the problem with this

djvdm123 @ 1 Mar 2011 01:48 PM

what's the problem with this code ??

gives me wrong answer

 

#include<iostream>

using namespace std;

int main()

{

int test[100],i=0;

for(i=0;i<100;i++)

{

cin>>test[i];

if(test[i]==42)

{

cin>>test[++i];

break;

}

}

int j=i;

for(i=0;i<j;i++)

cout<<test[i]<<endl;

 

return 0;

@gunjan #include<stdio.h> int

fluteofcoder @ 1 Mar 2011 10:02 PM

@gunjan

#include<stdio.h>

int main()

{

int a;

while(1)

{

printf("%d",a);//printing garbage value?

scanf("%d",&a);

if(a=42)

break;

}

}

i m beginner help me out

@dhruv what's the problem

fluteofcoder @ 1 Mar 2011 10:06 PM

@dhruv

what's the problem with this code ??

gives me wrong answer

 

#include<iostream>

using namespace std;

int main()

{

int test[100],i=0;

for(i=0;i<100;i++)

{

cin>>test[i];

if(test[i]==42)

{

cin>>test[++i];

break;

}

}

int j=i;

for(i=0;i<j;i++)

cout<<test[i]<<endl;

 

return 0;

//its not neccessary to first print all input and then their respective output

you can do something like this..lets say user enter i/p x whose o/p is y

x

y(after pressing enter)

#include<stdio.h>void

parthrajsingh @ 1 Mar 2011 10:26 PM

#include<stdio.h>

void main()
{
int i;

while(1)
{
scanf("%d",&i);
if (i==42)
break;
else
printf("%dn",i);
fflush(stdin);
}

}

 

-- I have submitted above program but i got run time error without fflush(stdin) and got compilation error with that statement.

-- As our program is checked by some software. It might be using predefined inputs files for testing our program. It might be storing output to some other temporary file. And then might be comparing that with some permanent files for specific inputs file. So, if this is the case then it should give correct result.

-- Can anybody help me to understand the reason of errors I got or otherwise tell me what I am missing who so ever has successfully submited this program.

#include<stdio.h>void

parthrajsingh @ 1 Mar 2011 10:28 PM

#include<stdio.h>

void main()
{
int i;

while(1)
{
scanf("%d",&i);
if (i==42)
break;
else
printf("%dn",i);
fflush(stdin);
}

}

 

-- I have submitted above program but i got run time error without fflush(stdin) and got compilation error with that statement.

-- As our program is checked by some software. It might be using predefined inputs files for testing our program. It might be storing output to some other temporary file. And then might be comparing that with some permanent files for specific inputs file. So, if this is the case then it should give correct result.

-- Can anybody help me to understand the reason of errors I got or otherwise tell me what I am missing who so ever has successfully submited this program.

-- Is there any IDE which works similar to Software checking our problem.

//WHY IT IS RUNTIME ERROR?  I

h2010445 @ 6 Mar 2011 08:30 PM

//WHY IT IS RUNTIME ERROR?  I DID NOT GET............I APPRECIATE YOUR FEEDBACK..............

 

#include<stdio.h>

void main(){

int a[5];

int i;

 

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

scanf("%d",&a[i]);

}

 

//for comparision

 

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

if(a[i]==42)

break;

printf("n%d",a[i]);

}

}

#include<iostream.h> #include

rohini3034 @ 7 Mar 2011 12:50 PM

#include<iostream.h>

#include<conio.h>

void main()

{

int i;

for(;;)

{

cin>>i;

if(i==42)

break;

cout<<i;

}

getch();

}

First Read FAQ!

rajneesh2k10 @ 7 Mar 2011 05:46 PM

First Read FAQ!

PLEASE TELL...WHY THIS CODE

sanjutagra @ 13 Mar 2011 01:40 AM

PLEASE TELL...WHY THIS CODE IS NOT WORKING???

#include<stdio.h>

#include<stdlib.h>

typedef struct node

{

int no;

struct node *link;

}node;

main()

{

int num;

node *temp,*start,*temp1;

temp=(node *)malloc(sizeof(node));

start=temp;

do

{

scanf("%d",&num);

if(num==42)

{

temp==NULL;

break;

}

else

{

temp->no=num;

temp1=(node *)malloc(sizeof(node));

temp->link=temp1;

temp=temp1;

}

}while(1);

temp=start;

while(temp!=NULL)

{

printf("%dn",temp->no);

temp=temp->link;

}

}

 

 

i''ve submitted the correct

bharathreddy @ 13 Mar 2011 08:25 AM

i''ve submitted the correct code .....i've checked it twice but the submission is producing run time error....plz reply

This is my solution in

arudhatt @ 14 Mar 2011 05:13 PM

This is my solution in Java

public class Life{

 public static void main(String[] args){

 java.io.BufferedReader in = new java.io.BufferedReader (new java.io.InputStreamReader (System.in));

 String str = in.readLine();

 while(!str.startsWith("42"))

 System.out.println(str);

 }

}

#include<stdio.h> main(){ int

balhotra_07 @ 15 Mar 2011 11:35 PM

#include<stdio.h>
main()
{
int n,t;
while(t--)
{
scanf("%d",&n);
if (n==42)
{
break;
}
else
printf("%dn",n);
}

return 0;
}

The example was not clear

blackrainbow @ 16 Mar 2011 02:20 PM

The example was not clear enough first. :)

#include<stdio.h> main(){ int

ashwani_singhj @ 18 Mar 2011 10:57 AM

#include<stdio.h>
main()
{
int n,t;
while(t--)
{
scanf("%d",&n);
if (n==42)
{
break;
}
else
printf("%dn",n);
}

return 0;

}

import java.util.*; class

raj23dev @ 19 Mar 2011 01:33 PM

import java.util.*;

class TEST

{

public static void main(String args[])

{

Scanner s =new Scanner(System.in);

int x=s.nextInt();

 

while(x!=42)

{

System.out.println(x);

x=s.nextInt();

}

System.exit(1);

}

}

why isnt this not being accepted...???

#include<conio.h> #include<io

sharadr19 @ 22 Mar 2011 07:19 PM

#include<conio.h>

#include<iostream.h>

main()

{

clrscr();

int a[5];

for(int i=0;i<5;i++)

{

cout<<"Enter The No."<<endl;

cin>>a[i];

}

for(int i=0;i<3;i++)

{

cout<<a[i]<<endl;

}

getch();

 

}

import java.util.*; class

soumit @ 31 Mar 2011 01:28 AM

import java.util.*;

class A

{

Scanner in=new Scanner(System.in);

int e[]=new int[10];

public void setArray()

{

for (int i=0; i<10; i++)

{

e[i]=in.nextInt();

}

System.out.println("n");

}

public void getArray()

{

for(int i=0; i<10; i++)

{

if (e[i]==42)

{

break;

}

System.out.println(e[i]);

}

}

public static void main(String a[])

{

A w=new A();

w.setArray();

w.getArray();

}

}

 

Can someone explain how to

default1130 @ 1 Apr 2011 12:37 PM

Can someone explain how to write asm code for this problem?

Thanks

#include<stdio.h>int

moinkhan @ 3 Apr 2011 02:35 PM

#include<stdio.h>
int num[2];

int main()
{  
int a;
int i;

i=0;
while(scanf("%d",&a)==1)
{
if(a == 42) break;
else num[i] = a;
i++;
}

for(i=0; i<sizeof(num); ++i)
{
if(num[i]== 0) break;
else printf("%dn",num[i]);
}

return 0;
}

 

why this code is not taken as the solution of this problem

Hey check me if i am wrong

sak3t @ 3 Apr 2011 11:04 PM

Hey check me if i am wrong .....

The sample input output is displayed wrong...

it should be like this

Input: 4

Output: 4

Input: 56

Output: 56

Input: 32

Output: 32

Input: 87

Output: 87

Input: 42

 

 

right?

#include<conio.h>#include<ios

codebuster1 @ 6 Apr 2011 10:40 PM

#include<conio.h>
#include<iostream.h>
void main()
{
int n;
cin>>n;
if(n!=42)
{

cout<<n;
}
getch();
}

#include<iostream.h>void

ajanacool @ 7 Apr 2011 02:31 AM


#include<iostream.h>
void main()
{
int n;
cin>>n;
if(n!=42)
{

cout<<n;
}
getch();
}

hahaha!!!! this is real

kshawa @ 7 Apr 2011 12:19 PM

hahaha!!!!

this is real crap...
this question's solution as submitted by other users is literally wrong..
bcoz

see the input in question:
"1

2
88
42
99
"
frm this it means that a user can enter a number beyond 42....
after that it would check uptil 42 and then it would print...

but most users have posted answers where you cannot enter a number after 42 , as it breaks from there and exits..
so the question is wrong

  Can anyone help me out with

msichael @ 8 Apr 2011 02:39 AM

 

Can anyone help me out with this problem?

 

:: CODE STARTS ::

 

 

<?php

while (true)

{

$line = fgets(fopen ("php://stdin','r'"));

if(trim($line) != '42')

{

echo trim($line) . 'n';

}

else

{

break;

}

}

?>

 

 

:: CODE ENDS ::


I am getting "Time Limit exceeded" after I submit the above code.

 

Can anyone point out, how can I optimize the code to make it work before the defined time limit?

Thanks in advance.

 

Regards,
Michael.

Anyways, I solved it!!!::

msichael @ 8 Apr 2011 03:01 AM

Anyways, I solved it!!!

:: Optimized CODE STARTS ::

<?php

while (1)

{

$line = trim(fgets(STDIN));

if($line != '42')

{

fwrite(STDOUT, $line."n");

}

else

{

break;

}

}

?>

 

:: CODE ENDS ::

Regards,
Michael.

plc tell me what is wrong

chami @ 8 Apr 2011 05:24 PM

plc tell me what is wrong with this it gives run time error bt i cant figure it out.

 

#include <iostream>

using namespace std;

int main(void){

int inputNum = 0 , validater = 0;

while(true){

cin >> inputNum;

if(inputNum == 42)

validater = 1;

if(inputNum != 42 && validater == 0)

cout << inputNum << endl;

}

return 0;

}

plc tell me what is wrong

chami @ 8 Apr 2011 05:24 PM

plc tell me what is wrong with this it gives run time error bt i cant figure it out.

 

#include <iostream>

using namespace std;

int main(void){

int inputNum = 0 , validater = 0;

while(true){

cin >> inputNum;

if(inputNum == 42)

validater = 1;

if(inputNum != 42 && validater == 0)

cout << inputNum << endl;

}

return 0;

}

@Chaminda Sampath in very 1st

shashgibbs88 @ 8 Apr 2011 06:51 PM

@Chaminda Sampath

in very 1st line...

->#include<iostream.h>

#include <stdio.h> #include

sakshijain2590 @ 9 Apr 2011 06:54 PM

#include <stdio.h>

#include <conio.h>

 

void main()

{

int i=0;

while ( i!= 42)

{

scanf ("%d", &i);

printf ("%d", i);

}

getch();

clrscr();

}

import

kk321 @ 9 Apr 2011 07:21 PM

import java.util.Scanner;

class BruteForce

{

 public static void main(String arg[])

{

int i=0;

int A[]=new A[99];

Scanner in=new Scanner(System.in);

System.out.println("enter any no in 2 digits max:");

while(i<=99)

{

if(A[i]!=42)

{

System.out.println(A[i]);

}

else

break;

}

}

}

#include<iostream.h> main() {

punit412 @ 10 Apr 2011 09:20 AM

#include<iostream.h>

main()

{

int a[5];

for(int i=0;i<5;i++)

{

cout<<"Enter the 2 digit no. "<<i<<endl;

cin>>a[i]

}

for(i=0;i<5;i++)

{

if(a[i]!=45)

{

cout<<a[i]<<endl;

}

else

return 0;

 

}

}

#include<iostream.h> main() {

punit412 @ 10 Apr 2011 09:25 AM

#include<iostream.h>

main()

{

int a[5];

for(int i=0;i<5;i++)

{

cout<<"Enter the 2 digit no. "<<i+1<<endl;

cin>>a[i];

}

for(i=0;i<5;i++)

{

if(a[i]!=45)

{

cout<<a[i]<<endl;

}

else

return 0;

 

}

}

#include<stdio.h>int

dharamdas123 @ 10 Apr 2011 10:23 AM

#include<stdio.h>

int main()

{

int x;

for(;;)

{

scanf("%d",&x);

if(x>0&&x<100&&x!=42)

printf("%dn",x);

else

break;

}

return 0;

}

//You should enter the number except the 42 then it will execute successfull

#include<stdio.h>void

dharamdas123 @ 10 Apr 2011 10:26 AM

#include<stdio.h>
void main()

{

int x;

for(;;)

{

scanf("%d",&x);

if(x!=42)

printf("%dn",x);

else

break;

}

}

import java.util.*;class

ankit_bhopal88 @ 10 Apr 2011 11:33 AM

import java.util.*;
class BruteForce
{
public static void main(String []args)
{
Scanner kb=new Scanner(System.in);
int i,len=0,a[]=new int[30];
do
{
a[len]=kb.nextInt();
len=len+1;
}
while(a[len-1]!=42);
for(i=0;i<len-1;i++)
{
System.out.println(a[i]);
}
}
}

#include<iostream.h> #include

son14ali @ 10 Apr 2011 11:39 AM

#include<iostream.h>

#include<conio.h>

int main()

{int a[100],i,ch;

{cout<<"enter the nos:n";

{

for(i=0;i<100;++i)

cin>>a[i];

if(a[i]==42)

break;

]

ch=i;

}

for(i=0;i<ch;++i)

cout<<"n"<<a[i];

getch();

}

 

 

 

#include<stdio.h> #include<co

teamforce @ 10 Apr 2011 11:51 AM

#include<stdio.h>

#include<conio.h>

void main()

{

int a[100],i,n;

printf("enter the nos = ");

for(i=0;i<100;i++)

{

scanf("%d",&n)

if(n==42)

break;

a[i] = n;

}

n=i;

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

printf("%dn"a[i]);

getch();

}

#include<iostream.h> #include

mesker @ 10 Apr 2011 11:53 AM

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int a,i=0;

while(i!=42)

cout<<i;

i++;

}

getch();

}

#include<iostream.h> #include

mesker @ 10 Apr 2011 12:05 PM

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int a,i=0;

while(i!=42)

{

cout<<i;

i++;

}

getch();

}

#include<stdio.h> int

itworriers @ 10 Apr 2011 02:26 PM

#include<stdio.h>

int main()

{

int i

while(i!=42)

{

printf("enter a two digit number");

scanf("%d",&i);

printf("%d",i);

}

return 0;

}

class number { public static

rije1234 @ 10 Apr 2011 03:22 PM

class number

{

public static void main(String []s)

{

s[]={1,2,88,42,77};

for(int i=0;i<=s.length-2;i++)

{

System.out.println(s);

}

}

}

using System; using

fez_kat123 @ 11 Apr 2011 03:09 AM

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace democonsole

{

class Program

{

static void Main(string[] args)

{

 

int[] a = new int[5];

 

a[0] = 1;

a[1] = 2;

a[2] = 88;

a[3] = 42;

a[4] = 99;

 

 

 

 

 

System.Console.WriteLine("nn");

 

for (int i = 0; i < 4; i++)

{

if (a[i] != 42)

{

 

System.Console.WriteLine(a[i]);

}

else

break;

 

}

 

 

 

 

Console.ReadKey();

 

}

 

}

}

 

whats the error here mate any one

#include <stdio.h> #include

akhilkashok1 @ 11 Apr 2011 09:44 PM

#include <stdio.h>

#include <stdlib.h>

int main()

{

int i;

for(;;)

{

scanf("%d", &i);

if(i != 42)

{

printf("%dn", i);

}

else

{

return 0;

}

}

system("PAUSE");

}

void main(){ int i=0;

summved @ 11 Apr 2011 11:32 PM

void main()

{

int i=0;

while(1)
{

printf("Enter your number");
scanf("%d",&i);

if(i==42)   
break;

else
printf("%d",i);   

}   



}

#include "stdio.h"   int

akankshav @ 13 Apr 2011 07:52 PM

#include "stdio.h"

 

int main(){

int i;

for(;;){

scanf("%d", &i);

 

if(i != 42){

printf("%dn", i);

} else {

return 0;

}

}

}

#include<stdio.h> #include<co

master_coder @ 14 Apr 2011 11:12 AM

#include<stdio.h>

#include<conio.h>

void main()

{

int a[10]={0},i=-1,j;

 

do

{

scanf("%d",&a[++i]);

}while(a[i]!=42);

for(j=0;j<i;j++)

printf("%d",a[j]);

getch();}

whats the difference in

emtx @ 14 Apr 2011 05:25 PM

whats the difference in coding in turbo c++ and a gcc  compiler i am not used to gcc compiler what are the things that i should atleast know to code in gcc compiler and compile my code?

Hii....I'm using Dev C++ for

bornrocking @ 14 Apr 2011 10:43 PM

Hii....

I'm using Dev C++ for coding problems....

Which Language I should select from the drop down menu for submitting the code on my profile....

there's no option for DEV C++....

I've compiled the code on my PC successfully.....

Please help me out....

@Prerit Anwekar - GCC

bornrocking @ 14 Apr 2011 10:44 PM

@Prerit Anwekar - GCC compiler is a Linux based editor for C++....

#include<stdio.h> #include<co

amitgodre @ 15 Apr 2011 11:37 AM

#include<stdio.h>

#include<conio.h>

void main()

{

int i;

printf("ENTER NUMBER = n");

scanf("%d",i);

while(1)

{

if(i!=42)

printf("%d",i);

else

break();

}

}

#include<stdio.h> #include<co

amitgodre @ 15 Apr 2011 11:47 AM

#include<stdio.h>

#include<conio.h>

void main()

{

int i;

printf("ENTER NUMBER = n");

scanf("%d",i);

while(1)

{

if(i!=42)

printf("%d",i);

else

break();

}

}

#include<stdio.h>int

newdeveloper @ 15 Apr 2011 03:03 PM

#include<stdio.h>

int main(void)

{

unsigned int num;
int n;

printf("Enter no of integer: ");
scanf("%d",&n);

for(int i=0i<n;i++)
{
printf("Enter the 2 digit positive no. :");
scanf("%d",&num[i]);
if(num[i]>99 | num[i]<0)
{
printf("Error in input");
exit(0);
}
}

for(i=0i<n;i++)
{
printf("Enter 2 digit positive no.");
scanf("%d",&num[i]);
if(num[i]==42)
break;
}
return(0);

}

#include<stdio.h> int

mayankmayank @ 16 Apr 2011 06:18 PM

#include<stdio.h>

int main()

{

int a;

for(;;)

{

cin>>a

if(a==42)

break;

else

cout<<a;

}

 

}

@Codechef, how do you check

harish_8080 @ 17 Apr 2011 01:11 AM

@Codechef, how do you check the Mem?

I've submitted the same code in C as others with 0M did. But it shows me 1.6M? Why?

Is this something to do with browsers?

Please help, I've competition on 20th april and this will really help me.

import java.io.*; public

pkpeeyush @ 23 Apr 2011 09:49 PM

import java.io.*;

public class NewClass

{

public static void main(String args[])throws IOException

{

int a;

do{

DataInputStream in=new DataInputStream(System.in);

a=Integer.parseInt(in.readLine());

System.out.println(a);

} while (a != 42);

}

}

#include<stdio.h>#include<con

jituo007 @ 30 Apr 2011 11:16 PM

#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf("PLEASE ENTER ANY INTEGER NUMBER OF ONE OR TWO DISITS ");
do
scanf("%d",&n);
while(n!=42);
printf("nn42 found!!!nnPLEASE PRESS ANY KEY TO EXIT");
getch();
}

puts "Input integers of one

sharief_shaik @ 2 May 2011 08:04 PM

puts "Input integers of one or two digits separated by space."
input = gets.chomp
input.split(" ").each do |n|
exit if n.to_i == 42
puts n
end

ARGV.each do |n|
puts n
exit if n == 42
end

//Program for inputing 10

hpandey @ 4 May 2011 12:13 PM

//Program for inputing 10 numbers at a time
//it terminates and print the entered numbers before the digit 42
import java.util.Scanner;

public class Test1
{
static Scanner sn=new Scanner(System.in);


public static void main(String[] args)
{
int[] arr=new int[10];
int num; 
System.out.println("Enter two digit numbers:");
{
num=(int)Integer.parseInt(""+sn.next());
for(int i=0;i<arr.length;i++)
{
if(num!=42)
{
arr[i]=num;
num=(int)Integer.parseInt(""+sn.next());
}
else
break;
}
System.out.println("Entered numbers are:");
for(int i=0;i<arr.length;i++)
{
if(arr[i]!=42) 
{

if(arr[i]==0)
{
break;
}
System.out.println(arr[i]);
}  
else
{ 
break;
}

}
}
}
}
//It's Hp

import java.util.*; public

pranavcodes @ 10 May 2011 09:15 PM

import java.util.*;

public class BruteForce

{

public static void main(String s[])

{

Scanner sc=new Scanner(System.in);

int i=0;

while(1)

{

i=sc.nextInt();

if(i==42)

break;

System.out.println(i);

}

}

}

this is the correct code in

fahadzaman @ 11 May 2011 05:12 PM

this is the correct code in C

written in DEV C++ Compiler

frist time it wsnt accepted because i didnt choose the Language C in the submit page, so beaware..

 

#include<stdio.h>
//#include<conio.h>

int main()

{
int i;

while (scanf("%d",&i))
{
if (i==42)
{
break;
}
else
{
printf("%dn",i);
}
}

//getch();
return 0;
}

#include<stdio.h>int

satish970 @ 13 May 2011 04:05 PM

#include<stdio.h>
int main()
{
int a;
for(;;)
{
scanf("%d",&a);
if(a!=42)
{
printf("%dn",a);
}
else
{
break;
}
}
}

WHATS WRONG WITH IT IAM GETTING RUNTIME ERROR

#include <stdio.h> int

kewlcoder @ 15 May 2011 03:44 PM

#include <stdio.h>

int main()

{

int i =0;

while(i != 42)
{
scanf("%d", &i);
printf("%d", i);
}

}

#include <stdio.h> void

kewlcoder @ 15 May 2011 03:57 PM

#include <stdio.h>

void main()
{
int i = 42;
scanf("%d", &i);
while( i != 42)
{
printf("%dn", i);
scanf("%d", &i);
}
}

You have asked that stop

surendergora @ 17 May 2011 11:33 AM
You have asked that stop processing inputs after reading 42. But i viewed the solutions of others , they have stopped their loop after 42 & didnt take input after that which i think is wrong because if i give input after 42, it should show no result. And also how to end the loop ??? Please answer...!!

i agree with surendargora i

phalgun @ 18 May 2011 05:41 PM
i agree with surendargora i too checked the solutions provided by others and i found the same..

how many inputs we have to

architm @ 19 May 2011 09:00 PM
how many inputs we have to take

What is the time limit means

mohd_kashif @ 24 May 2011 10:55 PM
What is the time limit means here...? Does it mean to write the code within the limit..?

I tested sample solution it

latebloomer @ 29 May 2011 03:01 PM
I tested sample solution it is not producing the right o/p still it is accepted #include int main(void) { int x; for(; scanf("%d",&x) > 0 && x != 42; printf("%dn", x)); return 0; } o/p is 11 11 88 88 54 54 which is incorrect

#include int main() { int

sampath_o2 @ 2 Jun 2011 06:57 PM
#include int main() { int i; while(i!=42) { scanf("%d",&i); printf(" %dn",i]); } return 0; } i'm getting wrong answer for this code.can some one please tell why

nooo

satyam_mishra @ 11 Jun 2011 12:35 PM
nooo

can i know whats wrong with

sravya @ 22 Jun 2011 07:26 PM
can i know whats wrong with my code....i always get runtime error...what is runtime error...?? #include main() { int a; scanf("d",&a); while(a!=42) { printf("%d",a); scanf("%d",&a); } }

@sravya give me your code

hungrycoder @ 22 Jun 2011 10:50 PM
@sravya give me your code link..or move the cursor over the runtime error sign on ur submission...it will gv u a code like NZEC,SIGSEGV,SIGFPE,SIGABRT...TELL THE CODE OR SEARCH IT IN THE FAQ......OR IN WIKI....

@hungry

sravya @ 23 Jun 2011 11:58 AM
@hungry coder.....http://www.codechef.com/viewsolution/581684

@sravya cant u look at your

hungrycoder @ 23 Jun 2011 10:52 PM
@sravya cant u look at your code once again.Its a small one..please go through it and I m pretty sure that u ll thrash ur head against the wall after finding out what mistake u have done ,a basic silly mistake to get SIGSEGV(segmentation fault).......and also u ll get NZEC(non zero exit code)...do use int main and return 0 in furthur submission to avoid this...

@hungry coder...yeah..i got

sravya @ 25 Jun 2011 12:34 PM
@hungry coder...yeah..i got dat i shud use "int main" n "return 0".bt whats wrng wid void main.

Thats the point and one more

hungrycoder @ 25 Jun 2011 01:16 PM
Thats the point and one more thing u dint use %d in scanning....u just put "d",&a...thats a mistake worth SIGSEGV but as u gettin one NZEC it is not shown

void doesnt work fine coz gcc

hungrycoder @ 25 Jun 2011 01:18 PM
void doesnt work fine coz gcc expects a certain return from any fn.including main()

void main(void) { int

abhishek_gupta @ 28 Jun 2011 09:08 PM
void main(void) { int i=0; while(i!=42) scanf("%d",&i); }

seems like python programmers

shatu_bits @ 5 Jul 2011 06:00 PM
seems like python programmers are having a hard time. Even Basic solutions being rejected as runtime error(other). Please tell me if anything wrong is there? #!/usr/bin/env python3 def main(): listed = [] flag = 0 while True: s = input() if s == "": break elif s == '42': flag = 1 continue if flag == 0: listed.append(s) for i in listed: print(i) if __name__ == "__main__":main()

wow...gr8 editor ^^...

shatu_bits @ 5 Jul 2011 06:02 PM
wow...gr8 editor ^^... another try seems like python programmers are having a hard time. Even Basic solutions being rejected as runtime error(other). Please tell me if anything wrong is there? #!/usr/bin/env python3 def main(): listed = [] flag = 0 while True: s = input() if s == "": break elif s == '42': flag = 1 continue if flag == 0: listed.append(s) for i in listed: print(i) if __name__ == "__main__":main()

@shatu_bits import sys

nrkchaitanya @ 6 Jul 2011 10:33 AM
@shatu_bits import sys lines = sys.stdin.readlines() for line in lines: if line.rstrip() != "42": print line else: break

@nrkchaitanya... can you

shatu_bits @ 7 Jul 2011 09:42 PM
@nrkchaitanya... can you please tell me what wrong did i do?.. If the code is not readable i can mail you up.. It is just that i am tired of C/C++, so want to code the problems in Python this time

import java.io.*; class

kasim @ 11 Jul 2011 12:18 AM
import java.io.*; class LifeTheUniverseAndEverything { public static void main(String[] args) { while (true) { try { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str = br.readLine(); double num = Double.parseDouble(str); if (num == 42) { break; } } catch (IOException ioe) { System.out.println("Errorn" + ioe.getMessage()); } catch (NumberFormatException nfe) { break; } } } }

import java.io.*; class

kasim @ 11 Jul 2011 12:19 AM
import java.io.*; class LifeTheUniverseAndEverything { public static void main(String[] args) { while (true) { try { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str = br.readLine(); double num = Double.parseDouble(str); if (num == 42) { break; } } catch (IOException ioe) { System.out.println("Errorn" + ioe.getMessage()); } catch (NumberFormatException nfe) { break; } } } } //try this code, it works :)

what is wrong with my

nithinreddi @ 13 Jul 2011 05:03 AM
what is wrong with my code?? #include int main() { int i=0; int a[5]; for(i=0;i<5;i++) { scanf("%d",&a[i]); printf("%d",a[i]); if (a[i]==42) break; } }

#include int main() {

nithinreddi @ 13 Jul 2011 05:04 AM
#include int main() { int i=0; int a[5]; for(i=0;i<5;i++) { scanf("%d",&a[i]); printf("%d",a[i]); if (a[i]==42) break; } }

Whats wrong with this

alias_m2k @ 14 Jul 2011 08:49 PM
Whats wrong with this one? [code] #include int main() { int in_num = 0; while(in_num != 42) { scanf("%d",&in_num); if((in_num >= 0) && (in_num < 100)) { if(in_num == 42) { break; } printf("%dn",in_num); } else { continue; } } } [/code]

import java.util.*; public

sanjeev2838 @ 15 Jul 2011 05:44 PM
import java.util.*; public class problem1 { public static void main(String[] args) { Scanner read=new Scanner(System.in); int i=0,n; Vector a=new Vector(); System.out.println("input"); while((n=read.nextInt())!=42) {a.addElement(n); } System.out.println("output"); for(i=0;i

using System; using

nyrajiv @ 17 Jul 2011 09:36 AM
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace LifeUniverseandEverything { class Program { static void Main(string[] args) { int[] myNumbers = {1,2,88,42,99 }; for (int i = 0; i < myNumbers.Length; i++) { if (myNumbers[i] != 42) { Console.WriteLine(myNumbers[i]); } else { i = myNumbers.Length; } } Console.ReadLine(); } } }

using System; namespace

nyrajiv @ 17 Jul 2011 09:40 AM
using System; namespace LifeUniverseandEverything { class Program { static void Main(string[] args) { int[] myNumbers = {1,2,88,42,99 }; for (int i = 0; i < myNumbers.Length; i++) { if (myNumbers[i] != 42) { Console.WriteLine(myNumbers[i]); } else { i = myNumbers.Length; } } Console.ReadLine(); } }

plz tell me the error in my

prateekgupta95 @ 18 Jul 2011 08:26 PM
plz tell me the error in my code?? #include void main() { int i; scanf("%d",&i); if(i==42) printf("%d",i); }

@prateekgupta: u r missing

sherwin21990 @ 19 Jul 2011 08:32 PM
@prateekgupta: u r missing header file,a loop and u should not use void main but int main and have a return statement at the end

#include main() { int

sanjay2cse1064 @ 23 Jul 2011 02:29 AM
#include main() { int x; scanf("%d",&x); for(x=0;x<100;x++) { printf("%dn",x); if(x==42) break; } }

i hav run da code nd its

dvsh @ 23 Jul 2011 06:42 PM
i hav run da code nd its successful in my compiler......... dnt knw wat is needed??????? showing run time error..........

why runtime error for this

diveshdixit @ 23 Jul 2011 11:17 PM
why runtime error for this code.. i am not able to start my first-program with codechef import java.util.Scanner; public class Test { public static void main(String args[]) { Scanner in = new Scanner(System.in); while(in.nextInt()!=42) System.out.println(in.nextInt()); } }

import

bengiexd @ 25 Jul 2011 09:35 AM
import java.util.Scanner; public class CLife { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=0; while(true){ n=sc.nextInt(); if(n!=42) System.out.println(n); else break; } } }

import

bengiexd @ 25 Jul 2011 09:37 AM
import java.util.Scanner; public class CLife { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=0; while(true){ n=sc.nextInt(); if(n!=42) System.out.println(n); else break; } } }

why runtime error for this

invinsibles @ 26 Jul 2011 12:46 AM
why runtime error for this code.. i am not able to start my first-program with codechef import java.util.Scanner; public class Test { public static void main(String args[]) { Scanner in = new Scanner(System.in); while(in.nextInt()!=42) System.out.println(in.nextInt()); } }

what is the problem here pls

kashaf_mamoon @ 31 Jul 2011 01:28 PM
what is the problem here pls some one help me........................ #include main() { int a; for(;;;) { scanf("%d",&a); if(a==42) break; printf("%d",a); } }

pls help me to find the error

kashaf_mamoon @ 31 Jul 2011 01:30 PM
pls help me to find the error of this #include main() { int a; for(;;;) { scanf("%d",&a); if(a==42) break; printf("%d",a); } }

in this time limit exceed

ashk @ 31 Jul 2011 07:20 PM
in this time limit exceed ...hence try not to use scanf n printf on the same line in the for loop itself

http://www.codechef.com/views

puzzzles @ 4 Aug 2011 02:52 PM
http://www.codechef.com/viewsolution/615715 how do i reduce the time?

SOMEONE PLZ HELP ME WITH THE

rahulkumar7887 @ 5 Aug 2011 11:54 AM
SOMEONE PLZ HELP ME WITH THE TIME; I ALWAYS GET THE ERROR TIMELIMIT EXCEEDED.

admin plz suggest somthing

rahulkumar7887 @ 5 Aug 2011 11:55 AM
admin plz suggest somthing about ;how to reduce time.

@rahulkumar7887: you should

vijay91 @ 5 Aug 2011 01:46 PM
@rahulkumar7887: you should read the problem statement carefully and check your solution first on devcpp compiler....your solution went into infinite loop...just check where you made mistake....Best Luck...Happy Coding :)

@bhanu compilation error is

bhanu431 @ 7 Aug 2011 05:33 PM
@bhanu compilation error is coming ,how can i submit my code using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { for (int i = 0; i <= 99; i++) { if (i != 42) { MessageBox.Show(i.ToString()); } else break; } } } }

please help this is my first

bhanu431 @ 7 Aug 2011 05:34 PM
please help this is my first code and i am not able to submit it

class Nnmber { public static

anshuman5220 @ 8 Aug 2011 12:38 AM
class Nnmber { public static void main() { int num; console.writeline(""); if(num!=42) { num=int.parse(console.readline()); console.writeline(+num); } else break; } }

import java.util.*; public

sitanshu @ 8 Aug 2011 03:27 PM
import java.util.*; public class Main { public static void main( String args[] ) { Scanner scan = new Scanner( System.in ); int actualNumber = scan.nextInt(); while( actualNumber != 42 ) { System.out.println(actualNumber); actualNumber = scan.nextInt(); } } }

whats error in

saurabhzx @ 8 Aug 2011 11:28 PM
whats error in this........... #include int main(void) { int a[10],n,i; printf("enter the number of elements u want n"); scanf("%d",&n); printf("enter the number n"); for(i=0;i

saurabhzx: > whats error in

tomek @ 8 Aug 2011 11:41 PM
saurabhzx: > whats error in this [...] printf("enter the number of elements u want n"); You have a spelling error: "u want" should have been "you want". Also: see the first question in http://www.codechef.com/wiki/faq

#include int main() { int

blackdrifter @ 9 Aug 2011 11:06 AM
#include int main() { int a,i; scanf("%d",&a); for(i=0;a!=42;i++) { printf("%d",a); if(a==42) { printf("%d",a); break; } else scanf("%d",&a); } getch(); } Showing Runtime error ... Y?

Please can someone help as to

mohit2088 @ 10 Aug 2011 09:00 PM
Please can someone help as to what am i doing wrong in this. I have created solutions for several problems but not able to make them work on CodeChef. My solution for this problem is: http://www.codechef.com/viewsolution/622993

This is my first submission.

csecodechef @ 11 Aug 2011 09:21 PM
This is my first submission. I can share with all :Enjoy with practicing code. #include "stdio.h" int main() { int i=0; for(;;) { scanf("%d",&i); if(i==42) return 0; else printf("%dn", i); } } .................csecodechef

How come I can't submit the

ozmark @ 14 Aug 2011 11:29 PM
How come I can't submit the code? please help me with this, I'm just new here

can anyone tell what's the

think1ahead7_3 @ 18 Aug 2011 12:56 AM
can anyone tell what's the error in this code: class First { public static void main(String args[]) { int n[]=new int[args.length],i=0; for(i=0;i

#include void main(){ int

amitrishi13 @ 18 Aug 2011 05:11 PM
#include void main(){ int i; while(1) { scanf("%d",&i); if (i==42) break; else printf("%dn",i); } } why is a run time error

Why i use code on top , i get

rreewwqq123 @ 18 Aug 2011 10:34 PM
Why i use code on top , i get wrong result? Please help me!!!!

Its showing run time

gsmanu @ 21 Aug 2011 05:19 PM
Its showing run time error ..........

I am trying to upload the

klaasn @ 25 Aug 2011 01:23 AM
I am trying to upload the example test in clojure, but I get an execution timeout. Now the code is fast enough in local and I also think it is correct. I am uploading this file ******************** (ns codechef.core (:gen-class :main true)) (defn -main [] (doall (map println (take-while (fn [n] (not= n 42)) (map #(Integer/parseInt %) (line-seq (java.io.BufferedReader. *in*))))))) *********************

#include #include void

mohitbansalism @ 28 Aug 2011 10:22 PM
#include #include void main() {int a=0; scanf("%d",&a); while(a!=42) { printf('%d',a); scanf("%d",&a); } }

This is my

shade @ 29 Aug 2011 01:17 PM
This is my code...... #include #include int main() { int n; loop: scanf("%d",&n); if(n!=42){ printf("%d",n); goto loop;} else exit(1); return 0; } It shows the Runtime Error.Why ???? Which compiler will I use.

import java.io.*; class

falgunistar @ 31 Aug 2011 10:16 PM
import java.io.*; class Universe { public static void main(String args[]) { int i,count,c; int num[]=new int[10]; count=0; Console con=System.console(); System.out.println("Input"); for(i=0;i

main() { unsigned int

coolcolgeboy @ 5 Sep 2011 12:14 PM
main() { unsigned int num; while(scanf("%d",&num)) { if ( num == 42 ) break; else printf("%d n",num); } }

#include #include void

prashant26 @ 6 Sep 2011 09:18 PM
#include #include void main() { int inp,out; clrscr(); cout<<"inp="; cin>>inp; if (inp!=42) out=inp; cout<< out; else break; getch(); }

#include #include void

prashant26 @ 6 Sep 2011 09:18 PM
#include #include void main() { int inp,out; clrscr(); cout<<"inp="; cin>>inp; if (inp!=42) out=inp; cout<< out; else break; getch(); }

Can anyone tell me why we'll

prachi23_22 @ 8 Sep 2011 09:38 PM
Can anyone tell me why we'll have to use namespace

prachi namespace is used to

pre_4 @ 11 Sep 2011 07:25 PM
prachi namespace is used to get all liberay function of ant directory example - we use in c for printf n scanf then in the place of we can use using namespace std

unable to get question :(

pre_4 @ 11 Sep 2011 07:26 PM
unable to get question :(

#include int

vinumkd @ 14 Sep 2011 08:07 AM
#include int main(void) { unsigned int num; while(scanf("%d",&num)) { if(num==42) break; } return(0); }

All persons who have

lavikumargupta @ 18 Sep 2011 12:38 AM
All persons who have successfully submitted the code just copy and paste it. All have exactly same code... ;)

#include void main() { int

akshatsingh @ 22 Sep 2011 08:19 PM
#include void main() { int a; do { scanf("%d",&a); if(a<42 || a>42) { printf("%d",a); }while(a!=42); } it gives "run time error" where is the error , i am first time here so please help me.

y m i gettin runtime error 4

nikhilkbhat @ 23 Sep 2011 08:07 PM
y m i gettin runtime error 4 dis code #include main() { int i; do { printf("nEnter the no:"); scanf("%d",&i); }while(i!=42); }

#!/bin/bash for i in 1 2 88

varghesethomas @ 23 Sep 2011 08:38 PM
#!/bin/bash for i in 1 2 88 42 99 do if [ i -ne 42 ] then print "$i" else break fi done

#!/bin/bash for i in 1 2 88

varghesethomas @ 23 Sep 2011 08:43 PM
#!/bin/bash for i in 1 2 88 42 99 do if [ i -ne 42 ] then echo "$i" else break fi done

#include int main() { int

mady902 @ 25 Sep 2011 10:53 PM
#include int main() { int i,a; for(i=0;i<=5;i++) { scanf("%d",&a); if(a!=42) printf("%d",a); else return 0; } }

Please help me. What is the

abhi_1993 @ 2 Oct 2011 10:39 AM
Please help me. What is the problem with the following code: import sys, os ifd = open('standard input.txt','r') ofd = open('standard output.txt','w') list1 = [] for num in ifd: num = num.strip() list1 = list1 + [num] for items in list1: if int(items) != 42: ofd.write(items+'n') else: exit() ifd.close() ofd.close()

i have submitted the solution

cute @ 2 Oct 2011 05:38 PM
i have submitted the solution and is accepted but my confusion is that my solution works for 100 inputs exactly. but it may be possible that one number is repeated several time can u suggest me why my solution accepted

#include void main() { int

rakesh_yadav @ 2 Oct 2011 06:19 PM
#include void main() { int s; printf("n Enter the values:"); scanf("n%d",&s); while(s!=42) { printf("%dn",s); scanf("%d",&s); } } As given in ur solution program it is processing for 42 also and in my code it is not processing for 42 then why i am getting run time error

please reply

rakesh_yadav @ 2 Oct 2011 06:20 PM
please reply

please help me out i'm not

farceur @ 6 Oct 2011 01:47 PM
please help me out i'm not able to understand what wrong in this code after submission it shows arong answr import java.io.*; import java.util.*; import java.lang.*; public class Main extends Exception { public static void main (String[] args) { try{ int number; System.out.print("Enter the Number"); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); for(;;) { number=Integer.parseInt(br.readLine()); if(number==42) break; System.out.println(number); } } catch(Exception e) {} } }

please help me out i'm not

farceur @ 6 Oct 2011 01:48 PM
please help me out i'm not able to understand what wrong in this code after submission it shows arong answr import java.io.*; import java.util.*; import java.lang.*; public class Main extends Exception { public static void main (String[] args) { try{ int number; System.out.print("Enter the Number"); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); for(;;) { number=Integer.parseInt(br.readLine()); if(number==42) break; System.out.println(number); } } catch(Exception e) {} } }

#inlcude int main() { int

jasleenkb @ 9 Oct 2011 07:08 PM
#inlcude int main() { int a,b; do{ printf("Enter number:"); scanf("%d",&a) //checking for 1-or 2-digit input b=a/100; if(b!=0) { continue; } } while(a!=42) }

#include #include #include st

abhijain153 @ 12 Oct 2011 06:13 PM
#include #include #include struct cc { int main() { in

a

gabriella @ 14 Oct 2011 12:01 AM
a

@rakesh_yadav: you have to

amriteshanand @ 14 Oct 2011 11:40 AM
@rakesh_yadav: you have to follow general conventions to get it accepted.Like the main function should return 0 and the output should be exactly the same as expected don't write statements like printf("enter n"); see sample solution for better understanding.Go to http://www.codechef.com/wiki/sample-solutions .

#include //#include int

a1b1 @ 16 Oct 2011 12:19 PM
#include //#include int main() { int a[5]; for(int j = 0; j < 5; j ++) { scanf("%d", &a[j]); } for(int i = 0; i < 5; i ++) { if(a[i] == 42) { break; } printf("%dn", a[i]); } //system("pause"); return 0; } the system keep saying that is compilation error. why ? can some1 help me?

#include int main (void)

clapashiya @ 17 Oct 2011 01:44 PM
#include int main (void) { int i; for (1; i!=42;) { scanf("%d", &i); printf("%dn", i); } return 0; } when run in GCC shows wrong answer, can any1 help please !!! when run in TC shows runtime error. Please help

hey i've a problem in self de

saumitramallick @ 27 Oct 2011 11:39 AM
hey i've a problem in self de bugging #include int main() { #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); freopen("output.txt","w",stdout); #endif int i; scanf("%d",&i); if(i>=0 &&i<100 && i!=42) { printf("%dn",i); } } the problem is that my program is reading only the first entry of my input file plz someone do help me ,,its ma first submission

I am trying to write the code

kwa2 @ 30 Oct 2011 06:52 AM
I am trying to write the code in Python, but I don't know how to make it take a vertical list of numbers. I only know how to use a list (i.e. [1,2,3]) as input. How do I make it so that it will read in the vertical input?

Can anyone tell me WHY IS

ambujpandey @ 30 Oct 2011 12:39 PM
Can anyone tell me WHY IS this working. I was trying to check how much memory can be used in a program (I assume 64MB). But even int[10000][10000] is getting AC (which is greater than 64MB), whereas it is given in FAQ that it won't. Check my solution: http://www.codechef.com/viewsolution/717308

#include void main() { int

rohan_gada @ 31 Oct 2011 03:32 PM
#include void main() { int a[5]; int i; cout<<"Enter numbers between 1-100 :"<>a[i]; cout<<"Output"<

#include #include void

abhiete @ 4 Nov 2011 08:57 PM
#include #include void main() { int input_no[10],i,o=0,l; clrscr(); printf("enter"); for(i=0;i<10;i++) { scanf("%d",&l); input_no[i]=l; o++; } for(i=0;i<=o;i++) { if(input_no[i]==42) {break;} printf("%d",input_no[i]); } getch(); }

#include #include void

ayushi2810 @ 13 Nov 2011 03:15 AM
#include #include void main() { int a[10],i; for(i=1;;i++) { scanf("%d",&a[i]); if(a[i]!=42) printf("%d",a[i]); else break; } getch(); }

#include #include void

nutdetnutdet @ 16 Nov 2011 07:56 AM
#include #include void main(){ int a; do{ scanf("%d",&a); if(a==42)exit(0); printf("%dn",a); }while(a!=42);}

Can anybody help why do i get

anurag1990 @ 20 Nov 2011 05:11 PM
Can anybody help why do i get this message?? Main.java:3: class ALUE is public, should be declared in a file named ALUE.java public class ALUE { ^ 1 error

why it did get

vivekkumar717 @ 20 Nov 2011 09:37 PM
why it did get accepeted import java.util.Scanner; public class abc { public static void main(String args[]) {int k=0; Scanner scan = new Scanner(System.in); while(k!=42) {k=scan.nextInt(); if(k!=42) System.out.println(k); } } }

class BruteForce { public

sag4u @ 22 Nov 2011 07:27 PM
class BruteForce { public static void main(String[] args) { if (args.length<=1) { System.out.println("insufficent args"); System.exit(0); } int[] num; num = new int[args.length]; System.out.println("The Input is :"); for (int i = 0 ;i99) { System.exit(0); } else { System.out.println(num[i]); } } } } // my code is correct but still its saying wrong why ?

import java.io.*; class

vision @ 29 Nov 2011 03:14 PM
import java.io.*; class ASM { public static void main(String args[]) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int[] i=new int[100]; int a=0,count=0; System.out.println("input:"); while((count=Integer.parseInt(br.readLine()))!=42) { i[a]=count; a++; } System.out.println("output:"); count=0; while(count

(No subject)

vision @ 29 Nov 2011 03:15 PM

/** * @(#)Solution.java *

canfkoyuncu @ 29 Nov 2011 11:00 PM
/** * @(#)Solution.java * * * @author * @version 1.00 2011/11/29 */ class Solution { public static void main(String [] args) throws java.lang.Exception { java.io.BufferedReader r = new java.io.BufferedReader (new java.io.InputStreamReader (System.in)); int a; while((a =Integer.parseInt(r.readLine())) != 42) System.out.println(a); } }

#include int main() {int

ravimistry_1 @ 30 Nov 2011 04:12 PM
#include int main() {int a; do{ printf("enter the number"); scanf("%d",&a); printf("%d",a); }while(a!=42); } why not running

#include "stdio.h" int

manasavalla @ 1 Dec 2011 04:18 PM
#include "stdio.h" int main(){ int i; a: scanf("%d", &i); if(i != 42){ printf("%dn", i); goto a; } else { return 0; } } }

Hi, The following code is for

yohanrw @ 4 Dec 2011 01:56 AM
Hi, The following code is for the first question inside "easy" mode, and it is 100% running on default JAVA compiler, so it is correct. But it is not running here, "Compilation Error". Why is that? Do I need to follow specific rules to submit here? If yes, please be kind enough to edit my code, then I can practically see what I have to do inorder to post in here import java.io.*; import java.util.*; public class ScanTest { private static Scanner scan; public static void main(String[]args) { scan = new Scanner(System.in); while(scan.hasNextInt()) { int a = scan.nextInt(); if(a==42) { break; } else { System.out.println(a); } } } }

i tried out the sample code

clinz @ 4 Dec 2011 08:40 PM
i tried out the sample code provided at the solutions page. And that code was accepted. But if that code is to be accepted as right then the question has to be modified!!! Because in the question we can enter a value ( 99 to be precise ) after entering 42, but in the sample code, we cannot enter a value after 42, yet it was ACCEPTED!!!

#include main() {

abhishekt @ 7 Dec 2011 05:44 PM
#include main() { int t; scanf("%d",&t); while((t!=42)&&(t<100)) { printf("%dn",t); scanf("%d",&t); } return 0; } why was this program giving runtime error when compiled in c and not when compiled in c++?

can anyone tell me, i'm

amitsuperman @ 13 Dec 2011 08:10 PM
can anyone tell me, i'm writing C programs in turboC compiler, thn what's my language, should i write C(gcc), i thnk my CODE is correct in TURBOC complier, and working there properly, it's showing RunTIME ERROR here....can i post my code here..?? and tell me what to do,??

#include int main() { int

amitsuperman @ 13 Dec 2011 08:16 PM
#include int main() { int x=0,flag=1; while(flag!=0) { scanf("%d",&x); if(x==42) flag=0; else continue; } return(0); } this is my code, why it isn't being accepted....??

#include main() { int

amitsuperman @ 13 Dec 2011 11:28 PM
#include main() { int x; while(scanf("%d",&x)) { if(x==42) break; else printf("%dn",x); } return; } wht's problem with this code...??

#include int main() {

raphael @ 14 Dec 2011 11:51 PM
#include int main() { int i;int number[100]; for(i=0;;i++) { scanf("%d",&number[i]); if(number[i]==42) break; } for(i=0;number[i]!=42;i++) printf("%dn",number[i]); } could u plz help me.it gives a run time error aftr submission

how to enter my code and

pritpari @ 15 Dec 2011 06:35 AM
how to enter my code and submit my solution to the programm

where to get gcc versions or

vabguds @ 19 Dec 2011 08:51 PM
where to get gcc versions or any ide with the required gcc's for c++?

How do you know when it ends?

iprogram_it @ 21 Dec 2011 02:05 AM
How do you know when it ends? After 99 I can keep entering numbers, who knows when it ends? I don't understand that. I'm doing it in c++, can someone clarify? or is it maximum 5 integers?

"i tried out the sample code

iprogram_it @ 21 Dec 2011 02:07 AM
"i tried out the sample code provided at the solutions page. And that code was accepted. But if that code is to be accepted as right then the question has to be modified!!! Because in the question we can enter a value ( 99 to be precise ) after entering 42, but in the sample code, we cannot enter a value after 42, yet it was ACCEPTED!!!" YES!!! Thanks, The question wasn't clear. Now I can easily do the program if that's the case.

This is STUPID!!! ALL my

iprogram_it @ 21 Dec 2011 03:28 AM
This is STUPID!!! ALL my submissions work, but only one equivalent to all the others work. WHY!?!? can someone explain to me why one works and the others don't IN TERMS OF THE WEBSITE'S REASONS. When I run it on codeblocks c++ it WORKs for all. FIX the website or clarify what I did wrong.

Great the meaning of life is

androidflo @ 21 Dec 2011 08:55 AM
Great the meaning of life is the number 42^^

i'm getting a run time error

r1d1_4 @ 23 Dec 2011 04:50 PM
i'm getting a run time error when i type d code below.. can any1 tell me y? #include int main() { int a[10],i; for(i=0;i<=9;i++) { scanf("%d",&a[i]); } for(i=0;i<=9;i++) { if(a[i]!=42&&a[i]<=99) printf("%d n",a[i]); else break; } }

#include main() { int

mkc450 @ 27 Dec 2011 02:11 PM
#include main() { int a[100],i; scanf("%d",&a[i]); for(i=0;i<100;i++) { if(a[i]=42) break; printf("%d",a[i]); } } whats wrong in this to get runtime error???

class abc {public static void

manol33 @ 27 Dec 2011 09:00 PM
class abc {public static void main(String args[]) {int i,j,n,c=42; n=args.length; for(i=0;i

#include void main() { int

verma007piyush @ 27 Dec 2011 11:03 PM
#include void main() { int num; while(1) { scanf("%d",&num); if (num!=42) printf("%d ",num); else break; } }

#include int main() { int

nagendrakaran @ 31 Dec 2011 01:21 AM
#include int main() { int i; while(scanf("%d",&i)!=42) { printf("%d",i); } return 0; } CAN ANYONE TELL ME WHAT IS THE PROBLEM WITH THIS CODE

how am i wrong can anyone

shadow123m @ 4 Jan 2012 09:41 AM
how am i wrong can anyone help?...... import java.util.Scanner; public class Main{ public static void main (String[] args){ Scanner a = new Scanner(System.in); int x = 1; do{ x = a.nextInt(); if (x == 42){ break; } else System.out.println(x); }while (x <=42); } }

#include int main() { int

nikhilbhartiya @ 4 Jan 2012 05:00 PM
#include int main() { int n; while(1) { scanf("%d",&n); if (n==42) return ; } } its giving "Runtime Error"..!! can any one tell me why???

Sir i have doubt in these

guptanitin @ 7 Jan 2012 09:13 PM
Sir i have doubt in these question : According to test case one should enter first all the input then it will output according to condition But How we reconize the end of the input? second thing is that ; i have went through solution given by member whos simply take input and shows output one by one integer upto 42 but this is voilated the question input example pls tell me wt your code wants? hurry

Why does it allow you to

lodankai @ 9 Jan 2012 07:57 AM
Why does it allow you to submit languages that are not listed?

it is not recognizing header

rashmi9pitdo @ 11 Jan 2012 05:35 PM
it is not recognizing header file... pls help #include void main() { int data; while(1) { cin>>data; if(data==42) break; cout<

how is this

sinhaanurag80 @ 12 Jan 2012 11:48 AM
how is this wrong?????#include int main() { int arr[1000],n,i; printf("enter the numbers you want"); scanf("%d",&n); for(i=0;i

#include void main() { int

niketkh @ 12 Jan 2012 09:33 PM
#include void main() { int a=0; cin>>a; for(;a!=42&&a<100;) { cout<>a; } } guys wht is wrng in this..............

#include int main(){ int

singhalkapil @ 14 Jan 2012 12:19 PM
#include int main(){ int num; for(;scanf("%d",&num),num!=42;printf("%d",num)); return 0; } frnds what is wrong with this code??

#include int main(void) { int

nishantsimply @ 14 Jan 2012 01:27 PM
#include int main(void) { int b; do{ printf("enter your number /n"); scanf("%d",&b); printf("%d/n",b); }while(b!=42); } //whats the run time error in this

what is compilation error all

surbhi289 @ 15 Jan 2012 02:13 PM
what is compilation error all about??????????

this seems like mumbo jumbo

trambilas1244 @ 16 Jan 2012 07:47 PM
this seems like mumbo jumbo to me. Can you tell me which program is best to learn c++ I hae dreamweaver on my pc can that help?

trambilas1244: last I heard,

jcomeau_ictx @ 18 Jan 2012 10:37 AM
trambilas1244: last I heard, Dreamweaver is for web development. Do a search for a programmer's editor or an IDE (integrated development environment). I prefer the former, but many younger programmers prefer the latter.

my code is giving compiling

codemink @ 19 Jan 2012 12:39 PM
my code is giving compiling error: #include #include int main() { int no; cout<<"Input Number: "; cin>>no; if(no>42)cout<

@codemink first check it on

sherepunjab @ 20 Jan 2012 05:56 PM
@codemink first check it on gcc. I think this is not correct.

why my prog is giving wrong

sinchan @ 21 Jan 2012 11:53 AM
why my prog is giving wrong answer??? help me!!

why it is not accepting the

z_01 @ 22 Jan 2012 12:21 AM
why it is not accepting the directory #include and giving a compilation error

#include int main() {int

jaskaran_1 @ 22 Jan 2012 02:52 AM
#include int main() {int n; scanf("%d",&n); while(n!=42) {printf("%dn",n); scanf("%d",&n); } }what's the problem in the code its working fine on my compiler dev bloodshed

could someone help me

noah_g22 @ 22 Jan 2012 02:54 PM
could someone help me please...I'm getting a run time error but my sorce code works fine in my laptop..I'm using C-Free version 4.1

Why am i getting a Run Time

vyppi @ 24 Jan 2012 12:29 AM
Why am i getting a Run Time Error??????

my code is : #Python. I don't

suryak @ 26 Jan 2012 09:35 AM
my code is : #Python. I don't understand what's wrong with this code.. can anyone explain??? please num_list = raw_input('').split() for walk in num_list: if walk == '42': break print walk

Can anyone tell me whats

suraj_subba @ 1 Feb 2012 04:23 PM
Can anyone tell me whats wrong in my code. Its saying run time error. #include int main() { printf("Enter Numbers n"); int i,num = 0, index = 0; int arr[200]; while(1) { scanf("n%d",&num); if(num < -99 || num > 99) break; arr[index] = num; index++; } for(i = 0 ; i < index ; i++) { if(arr[i] == 42) break; printf("n%d",arr[i]); } return 0; }

Been seeing "Oops, we

benfulton @ 2 Feb 2012 07:56 AM
Been seeing "Oops, we couldn't seem to load the successfull submission. " for a few days.

@suraj_subba : Dude u have

rrangan5 @ 2 Feb 2012 11:59 AM
@suraj_subba : Dude u have taken the array to be of size 200. The maximum number of inputs in this Question can be 50000. BTW, you do not have to store all the numbers in the array. Use the same variable num to store them and keep printing them. When it becomes 42 break out of the loop.

@suraj_subba: dont use

monikadaryani @ 2 Feb 2012 10:24 PM
@suraj_subba: dont use printf("Enter Numbers"); Dont use it ever in coding online.

public static void

nickelback @ 4 Feb 2012 11:03 AM
public static void main(String[] args) throws IOException { int num; int countDigits; boolean check = true; Scanner sc = new Scanner(System.in); while (true) { System.out.println("Enter the number"); num = sc.nextInt(); countDigits = (int) (Math.log10(num) + 1); if ((countDigits == 1) || (countDigits == 2)) { if (num == 42) { check=false; } if(check) { System.out.println(num); } } else { System.out.println("Caution...Does not satisfy the input critetia."); } } }

The program required is way

liltingmissive @ 5 Feb 2012 10:38 PM
The program required is way simpler than the description makes it sound. Here it is in pseudocode: main { int number = input from keyboard; while (number != 42) { print number to screen and end line; number = next input from keyboard; } }

#include #include

shiva1jee13 @ 6 Feb 2012 02:44 PM
#include #include #include void main { int a[100],i,n; printf("enter the no of terms u want to enter"); scanf("%d",&n); for(i=0;i

#include int main() { int

chakshu987 @ 7 Feb 2012 03:13 AM
#include int main() { int j; while(1) { scanf("%d",&j); printf("%d",j); if(j==42) break; printf("%dn",j); } return 0; } How cum numerous values are getting stored in d same variable j....?? since the scanf nd printf are in d same loop how is it first taking all d values nd den printing d required values...?? actually I m a beginner only so plzz answer even if its a silly query...

#include int main(){ int

peatea @ 8 Feb 2012 03:56 PM
#include int main(){ int n; while(scanf("%d",&n)){ if (n==42){ break; } printf("%d",n); } } it shows runtime error. what is wrong with this code?

hey can u tell whts wrong in

loveam @ 8 Feb 2012 06:06 PM
hey can u tell whts wrong in this: #include void main() { int a[15],i; printf("enter fifteen numbers"); for(i=0;i<=14;i++) scanf("%d",&a[i]); for(i=0;i<=14;i++) { if(a[i]==42); break; printf("%d",a[i]); } }

hey whts wrong in

loveam @ 8 Feb 2012 08:17 PM
hey whts wrong in this #include void main() { int a[15],i; printf("enter fifteen numbers"); for(i=0;i<=14;i++) scanf("%d",&a[i]); for(i=0;i<=14;i++) { if(a[i]==42); break; printf("%d",a[i]); } }

getting run time error for

codel @ 9 Feb 2012 01:46 PM
getting run time error for this code #include main() { int x; while( scanf ("%d", &x) > 0 && x!=42) { printf("%dn", x); } } don't know why......... its running perfectly on my computer

import

ankurtrapasiya @ 12 Feb 2012 11:23 PM
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; class Prog42 { public static void main(String[] args) throws IOException { String temp; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); while (!(temp = br.readLine()).startsWith("42")) { System.out.println(temp); } br.close(); } } When i am submitting this code i am getting error which says "Runtime Error". I checked the code completely but it is not giving me error at any point. Please tell me what to do in this case?

why my code is wrong? class

divya_dippi @ 19 Feb 2012 12:38 PM
why my code is wrong? class universe { public static void main(String args[]) { int i,k; k=args.length; try { for (i=0;args[i+1]!="42"&&i

#include int array(int); int

craztocode @ 19 Feb 2012 05:39 PM
#include int array(int); int main() {int arylen; printf("enter the value of the arrayn"); scanf("%d",&arylen); array(arylen); return(0); } int array(int x) { int a[x],i; for(i=0;i

#include #include void

jintojohnson @ 24 Feb 2012 01:47 PM
#include #include void main() { int l=0,i=0,num[100]; clrscr(); printf("n Enter the numbers less than 100n"); printf("press 100 to endn"); while(1) { scanf("%d",&num[i]); l++; if(num[i]==100) { l--; break; } i++; } for(i=0;i

#include void

avadhoot @ 24 Feb 2012 08:44 PM
#include void main() { printf("1"); printf("2"); printf("88"); }

#include int main(void) {

sowmyadharani @ 24 Feb 2012 10:01 PM
#include int main(void) { int n,i=0; clrscr(); for(i=0;;i++) { do{ scanf("%d",&n); }while(n!=42); if(n==42) break; } } it got executed in DOSBOX on my system but i have received a compile time error when i submitted this code...what has gone wrong?please tell me if anything wrong noticed

using System; using

salgaun7 @ 25 Feb 2012 04:43 AM
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace primero1 { class Program { static void Main(string[] args) { int numero = 0; while (numero != 42) { numero = int.Parse(Console.ReadLine()); if (numero < 100) { Console.WriteLine(numero); } else { Console.WriteLine("el numero ingresado es mas de dos digitos vuelva a digitar"); } } Console.WriteLine("has digiado 42 fin del programa"); System.Console.ReadLine(); } } }

but the program says only

salgaun7 @ 25 Feb 2012 05:22 AM
but the program says only enter two digit numbers.

Well... a clear explanation

archana_shiva @ 25 Feb 2012 05:47 PM
Well... a clear explanation of the program.... The user has to enter a no: The program checks if its 42 If its not then display immediately Repeat till you get 42 And for java programs... If you are entering the code in the editor dont give your class as public and dont specify any package name( which leads to runtime error)

where is the problem

snjivkmr @ 28 Feb 2012 05:48 PM
where is the problem ? #include void main() { int a; scanf("%d",&a); if(a!= 42) { printf("%dn",a); main(); } }

#include void main() { int

moneymayur @ 1 Mar 2012 04:09 PM
#include void main() { int n; printf("Enter a number less than 100"); scanf("%d",&n); if (n>99) printf("invalid input "); else if (n!=42) printf("%d",n); } what is the error in it its showing run time error

import java.util.*; class

codefreak007 @ 4 Mar 2012 01:57 PM
import java.util.*; class Stop_42 { public static void main(String...ar) { int n,number[]; Scanner sc=new Scanner(System.in); System.out.println("How many numbers do u want to enter?"); n=sc.nextInt(); number=new int [n]; for (int i=0;i

Hey guys am new to this group

n1x0rdon @ 5 Mar 2012 12:37 AM
Hey guys am new to this group an di don't know how their automated test works despite reading the FAQ. I test all my programs manually but when i upload it says Wrong answer. How can i collect the sample tests into my code? I use C.

#include void main() {

ashthecool @ 13 Mar 2012 01:29 AM
#include void main() { int j,i,a[10]; for(i=0;i<10;i++) { scanf("%d",&a[i]); } for(i=0;i<10;i++) { if(a[i]!=42&&a[i]<99) printf("%dn",a[i]); else break; } } whts the problem with this code ?? it gives runtime error

hello sir, i tried solving

bhawnaj @ 16 Mar 2012 09:31 PM
hello sir, i tried solving the problem , but it is displaying run time error. can you please help me rectify? #include #include int main(void) { int c; int x=0; while(scanf("n%d", &c)) { if(c == 42) { x=-1; } else { if(x== -1){} else { printf("%d",c); } } } getch(); return 0; }

hi why i am getting error

atulbnar @ 22 Mar 2012 12:27 PM
hi why i am getting error even my code runs successfully in my java ide or in command prompt but i am getting error in code chef please reply soon.bye

#include #include void

skdaksh011 @ 22 Mar 2012 10:29 PM
#include #include void main() { int a[20],i; printf("enter the 20 NUMBER="); for(i=0;i<20;i++) scanf("%d",&a[i]); printf("OUTPUT="); for(i=0;i<20;i++) { if(a[i]==42) break; else printf("n %d",a[i]); } getch(); }

http://www.codechef.com/views

akashaether @ 23 Mar 2012 03:46 PM
http://www.codechef.com/viewsolution/928407 getting a run time error ...any advice?

I hav done my work on Turbo

bhav1sharma1_3 @ 24 Mar 2012 02:43 PM
I hav done my work on Turbo C.....the code is running successfully there....so tell me how to submit it here...i mean in what format.

Tel me the error in this prog

praaveen @ 26 Mar 2012 01:14 AM
Tel me the error in this prog and i am getting time exceed... #include main() { int input,count=0; while(1) { scanf("%d",&input); if(input<100 && input != 42) { if(count==0) { printf("%d",input); } } else if(input == 42) { count=count+1; } else printf("enter < 100"); } }

Tel me the error in this prog

praaveen @ 26 Mar 2012 01:18 AM
Tel me the error in this prog and i am getting time exceed... #include main() { int input,count=0; while(1) { scanf("%d",&input); if(input<100 && input != 42) { if(count==0) { printf("%d",input); } } else if(input == 42) { count=count+1; } else printf("enter < 100"); } }

I tried to post a solution to

ysati_123 @ 28 Mar 2012 09:06 PM
I tried to post a solution to this problem in java through a file InputTest.java but it gives compiler error for wrong file name. However the same code is compiled and run successfully on my machine. and also works with the method of in.txt and out.txt as given in FAQs. Please help
1 of 2
next ›

SUCCESSFUL SUBMISSIONS


Fetching successful submissions

HELP



Program should read from standard input and write to standard output. After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:

 

  • Accepted Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark.

  • Time Limit Exceeded Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach.

  • Wrong Answer Your program compiled and ran succesfully but the output did not match the expected output.

  • Runtime Error Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section.

  • Compilation Error Your code was unable to compile. When you see this icon, click on it for more information.

  • If you are still having problems, see a sample solution here.
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.