Task: | Bittijono |
Sender: | ISIMO66 |
Submission time: | 2016-10-07 23:51:33 +0300 |
Language: | C++ |
Status: | READY |
Result: | 29 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 10 |
#2 | ACCEPTED | 19 |
#3 | RUNTIME ERROR | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.06 s | 1 | details |
#2 | ACCEPTED | 0.06 s | 2 | details |
#3 | RUNTIME ERROR | 0.13 s | 3 | details |
Compiler report
input/code.cpp: In function 'int main()': input/code.cpp:13:16: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long int*' [-Wformat=] scanf("%d", &j); ^ input/code.cpp:13:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &j); ^ input/code.cpp:16:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &input); ^
Code
#include <stdio.h> #include <stdlib.h> char * nextMember(char *, int *); int main(){ char * list = (char *)malloc(2 * sizeof(char)); int input; int i = 1; list[0] = '0'; list[1] = '\0'; long j; scanf("%d", &j); char * outList = (char *)malloc( j * sizeof(char)); for (long k = 0; k < j; k++){ scanf("%d", &input); start: if (input > i) { list = nextMember(list, &i); goto start; } outList[k] = list[input-1]; } for (long k = 0; k < j; k++){ printf("%c\n", outList[k]); } free(list); return 0; } char * nextMember(char * prev, int * i){ prev = (char *)realloc(prev, (*i * 2 + 1) * sizeof(char)); for (int j = 0; j < *i; j++){ if (prev[j] == '0') { prev[j + *i] = '1'; } else { prev[j + *i] = '0'; } } prev[*i * 2] = '\0'; *i = *i * 2; return prev; }
Test details
Test 1
Group: 1
Verdict: ACCEPTED
input |
---|
100 62 9 12 73 ... |
correct output |
---|
1 1 1 0 1 ... |
user output |
---|
1 1 1 0 1 ... |
Test 2
Group: 2
Verdict: ACCEPTED
input |
---|
100000 565433 141881 120108 825392 ... |
correct output |
---|
1 1 0 0 1 ... |
user output |
---|
1 1 0 0 1 ... |
Test 3
Group: 3
Verdict: RUNTIME ERROR
input |
---|
100000 374768524402011755 937067109466254318 389256426086302899 932585725667010169 ... |
correct output |
---|
0 1 1 1 1 ... |
user output |
---|
(empty) |