Every one is writing code only for the above input only.
It should not be like that na.
We have to sort all the numbers before 42 in ascending order (as mentioned in the question...."More precisely... rewrite small numbers from input to output").
Then we have to print all the numbers.
why everyone is writing the code without sorting?
or
Any problem with my way of understanding the question(let me know the correct way)??
and
why admin did consider the two digit input case as the program can accept any number na..????
Thanks in advance
There is nothing in this problem statement that says to sort the numbers.
"More precisely..." means that the statement to follow will make the previous statement more precise.
"rewrite small numbers from input to output"
Input is where the numbers are read from. Output is where the numbers get printed to. Rewrite means to copy. The problem is asking you to read the numbers from input and write them to output. Stop when the number is 42.
Keeping the numbers one or two digits keeps the problem simple. It also allows for some creative solutions.
If you need more clarification, please post again.
i wrote the following code
and in my terminal im getting the desired output but for some reason in the SPOJ its showing wrong answer
please help !! im net to SPOJ;
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a;
scanf("%d",&a);
while(a>0&&a!=42)
{
printf("%d",a);
scanf("%d",&a);
}
return 0;
}
Your code does not return the correct output for the sample input.
For this input:
1
2
88
42
99
Your code will print:
1288
The correct output is:
1
2
88
The difficulty that you are having is caused by the fact that you are using the console for input. The console allows you to type input to stdin as well as display output from stdout.
If you redirect your stdin and stdout to a file then you will accurately see what is being entered from stdin and being output to stdout.
To fix your output issue you should change your printf statement by adding a newline character to the end of it:
printf("%d\n",a);
Why have you chosen these conditions for your while loop?
while(a>0&&a!=42)
I got the same output as noix by implementing the following code but i get 'wrong answer' when i submit it on spoj please help me out
The Code:
#include<stdio.h>
int main()
{
int a=1;
while(a>0)
{
scanf("%d",&a);
if(a != 42)
printf("%d\n",a);
else
break;
}
}
The Code When ran in ideone gave same result!