include
int main()
{
int n, mq[1001], ms[1001], current, i, j=0;
scanf("%d", &n);
while (n>0)
{
for (i = 0; i<n; i++)
scanf("%d",&mq[i]);
current = 1;
for (i = 0; i<n; i++){
while(j>0 && ms[j]==current){
current++;
j--;
}
if (mq[i]==current){
current++;
}else{
j++;
ms[j] = mq[i];
}
}
while(j>0 && ms[j]==current){
current++;
j--;
}
if (current == n+1){
printf("%s","yes");
}else{
printf("%s","no");
}
scanf("%d", &n);
}
return 0;
}
why I receive RUN TIME ERROR? Please T_T
2 months later
1 month later
This solution no make sense, the solution don't does what it need do.
The code from Noix do:
input
output
input
output
... until you input 42
The problem ask you do
input
input
....until you input 42
output
output
...when 42 stop output.
someone for the love of GOD can explain me what you want we do in this problem ?
23 days later
2 months later
3 months later
This was my first question on spoj and i am highly demotivated towards competitve programming.
this was my code
#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.
1 month later
5 months later
I tried making as short as possible for fun and I had this:
for (short x = 0; x != 42; scanf("%hd", &x), (x != 42)&& printf("%hd\n", x));
return 0;
But initially I had this:
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <limits.h>
#define ERROR_RET_NULL(x) fprintf(stderr, "ERROR: %s returned NULL in file '%s' at line: %i.", x, __FILE__, (__LINE__ - 2))
int
main(void)
{
while (true)
{
short temp = 0;
char userInputString[5];
char *endPtr;
if (fgets(userInputString, 5, stdin) == NULL)
{
ERROR_RET_NULL("fgets");
exit(EXIT_FAILURE);
}
else
{
char *checkPtr = strchr(userInputString, '\n');
if (checkPtr) *checkPtr = '\0';
long numberToCastToShort = strtol(userInputString, &endPtr, 10);
if (numberToCastToShort > SHRT_MAX || numberToCastToShort < SHRT_MIN)
{
/* Given the size restriction on the string this is basically deadcode */
fprintf(stderr, "ERROR: number too big");
exit(EXIT_FAILURE);
}
else if (numberToCastToShort == 42) break;
else temp = (short) numberToCastToShort;
}
printf("%d\n", temp);
}
return 0;
}
2 months later
5 months later
1 year later
1 month later
1 year later