41 / 103
Oct 2012

The "sample input" is not the only test case that your code will be tested on.

Some other test cases:

42

1
2
3
4
4
5
5
6
7
8
9
42
12
12
13
9 months later
24 days later

include

include

void main()
{ int n;
while(1)
{ cin>>n;
if(n==42)
break;
cout<<"\n"< }
getch();
}

this is the code which i wrote but it shows a compilation error.can someone please tell me what is wrong with this code?

include

int main()
{ int n;
while(1)
{ cin>>n;
if(n==42)
break;
cout<<"\n"<}
return;
}

this is the edited code but this is also not working.it shows a compilation error.Could someone please give a sample code in c++ which will be accepted by spoj because when i compile it in my compiler then it shows no error.

If you click on compilation error it should give you more info. cin does not exist in the namespaces that you are using. Either use std::cin or at the top, after your includes,put:

using namespace std;

Please use code tags when posting code.

#include<iostream>
CODE: SELECT ALL
using namespace std;
int main()
{ int n;
while(1)
{ cin>>n;
if(n==42)
break;
cout<<"\n"<<n<<"\n";
}
return 0;
}

these are the errors it is showing after the correction
prog.cpp:2: error: function definition does not declare parameters
prog.cpp: In function 'int main()':
prog.cpp:7: error: 'cin' was not declared in this scope
prog.cpp:10: error: 'cout' was not declared in this scope

CODE: SELECT ALL

29 days later
4 months later

sir i am now working in dev c++ 4.9.9.2 and in which language i should summit my solution there is no option for this language

4 months later

include

include

int main()
{
int s;
for(;wink
{
cin>>s;
if (s!=42)
cout<else
break;
}
return 0;
}

The SPOJ judge shows compilation error and I'm not able to figure it out.

If you click on where it says compilation error it will show what the compilation error is.

1 year later

include

int main(void)
{
int n,c=0,i;
int a[c];
printf(" input \n");
while(1)
{
scanf("%d",&n);
a[c]=n;
if(a[c]==42)
break;
c++;
}
printf("OUTPUT \n");
for(i=0;i printf("%d \n",a[i]);
return 0;

i ran this code but its giving wrong answer .please help me to correct this code.I am not getting my mistake
}

include

int main(void)
{
int i[5],k;

for(k=0;k<=4;k++)
{
scanf("%d",&i[k]);
}

for(k=0;k<=4;k++){
if(i[k]!=42)
{printf("%d\n",i[k]);}
else break;	}return 0;

}

Hi Folks,

For the users that have most recently posted in this topic. Welcome!

Everything that you output will be considered for the answer, so this will cause WA.

cout << "enter the numbers" << endl;

Please use code tags when posting code (see the nice box around the code above?)

I see all of you assuming that there will be a certain number of inputs. djs1234 assumes that it will be less than or equal to 20. This is not true. The problem states that you should continue to take input until it reads 42, it does not say if there will be 5, 100, 10000000 numbers in the input.

while not done
  read input
  if number = 42 then done
  else print number
end while

include

using namespace std;
main()
{
int a[10], n=5, c;
cin >>n;
for(c=0;c {
cin >>a[c];
}
cout <<"the output is :- "<<"\n";
for(c=0;c {
if(a[c]!=42)
{
cout << a[c]<< '\n';
}
else
{
return 0;
}
};
return 0;
}

what the hell is wrong !!!
why it has not been accepted ... it is succesfully running in my compiler

Welcome! Please use code tags when posting code.

When you submit code to the judge, EVERYTHING that you output is considered for the answer. This line of code alone will fail your solution:

cout <<"the output is :- "<<"\n";

Once you have solved that you will then likely get a Runtime Error (SIGSEGV).
Nowhere in the problem statement does it say how many numbers there are in the input. There might be 2, there might be 100, there might be 1000000000. Because this is unknown you cannot store the input in memory. Also, the first number in the input is not the number of inputs to follow (n).

The information above makes this incorrect.

int a[10], n=5, c;
cin >>n;
for(c=0;c<n;c++)
{
cin >>a[c];
}

Please post back if you still have questions.