Reputation: 144
This was my first question on spoj,”test - Life, the Universe, and Everything” and i am highly demotivated towards competitve programming. This was my code and the link to the question is this
#include <iostream>
using namespace std;
int main()
{
int a[10],i;
for(i=0;i<10;i++)
{
cin>>a[i];
}
for(i=0;i<10;i++)
{
if(a[i]!=42)
cout<<a[i]<<endl;
else
break;
}
return 0;
}
It is running fine on codeblocks but is giving errors here on spoj. Please someone help me.
Upvotes: 0
Views: 147
Reputation:
This is my code hope it helps:
int n;
cin>>n;
while (!(n==42)) {
cout<<n<<"\n";
cin>>n;
}
Upvotes: 0
Reputation: 3632
As mentioned by the user he is solving some spoj problem just for the benefit of other user below is the requirement
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
Below is the code used (C++14) code worked in your online judge
Easiest way is just do this (working in you online judge) Keep taking input until you see 42 and then break
as suggested one of the user WhozCraig (please see comment)
int main()
{
int n;
while(std::cin >> n && n != 42)
std::cout << n << '\n';
}
Upvotes: 1