TEST - Life, the Universe, and Everything


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

Information

If you have some troubles with your code, you can take a look in the forum, you'll find the answer, only for this problem, in various languages.


Added by:Michał Małafiejski
Date:2004-05-01
Time limit:10s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel Pentium G860 3GHz)
Languages:All
Resource:Douglas Adams, The Hitchhiker's Guide to the Galaxy

hide comments
hellhammer: 2015-08-31 22:44:10

#include <iostream>

using namespace std;

int main()
{
unsigned int size;
cin>>size;
int cutoff =42;
int array[size];
for (unsigned int i=0;i<size;i++){
cin>>array[i];
if (array[i]!=cutoff)
cout<<array[i]<<endl;
else
return 0;
}
}

Shows WA here. Works fine on ideone and other offline compilers.

skrishna99: 2015-08-31 10:49:42

@adi_jalan ,check the input of only integer is accepted , I had the same problem when i used .scanner.hasnextint() the issue got resolved.

adi_jalan: 2015-08-27 07:46:24

My code is running perfect on my pc. But here it is showing compilation error

chinmayjoshi: 2015-08-25 16:22:20

check your header file ! :P

gmiller: 2015-08-24 16:43:42

Nice problem for beginners to understand input and output.

Last edit: 2015-08-24 16:48:21
Caps: 2015-08-22 10:45:10

@god_slayer, your loop takes in 1000 inputs. what if the user doesn't enter 1000 numbers, your program will be frozen there.

srikanth1303: 2015-08-19 15:51:31

value wont be entered into 'a' since '&' symbol is not used for addressing in scanf keyword.a will be taken garbage value and loop will become infiite loop

ROHIT Kumar: 2015-08-18 07:16:22

brute force dont think just do

Last edit: 2015-08-18 09:10:28
aishwarya_562: 2015-08-17 15:58:58

@isha_kiran , The problem is to print any random number entered except 42.Not the numbers less than or equal to 42. And when the user enters 42,the loop should break.Try rewriting the code :)

spandana538: 2015-08-17 08:56:35

my code is giving correct output but here showing compilation error why???


Problem's scores 2 votes

Concept difficulty
Concept difficulty 4%
Implementation difficulty
Implementation difficulty 5%
88 19