CSES - Datatähti 2022 alku - Results
Submission details
Task:Merkkijono
Sender:rixu
Submission time:2021-10-08 01:50:14 +0300
Language:C++11
Status:COMPILE ERROR

Compiler report

In file included from /usr/include/stdlib.h:566:0,
                 from /usr/include/c++/7/cstdlib:75,
                 from /usr/include/c++/7/stdlib.h:36,
                 from input/code.cpp:2:
input/code.cpp: In function 'int main()':
input/code.cpp:19:20: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
     char* string = alloca(length + 1);
                    ^
input/code.cpp:21:18: warning: value computed is not used [-Wunused-value]
     string[length];
     ~~~~~~~~~~~~~^
input/code.cpp:21:18: warning: statement has no effect [-Wunused-value]

Code

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#pragma GCC diagnostic ignored "-Wunused-result"

unsigned long function(unsigned long x) { return x*x-x+1; }

int main()
{
    unsigned long n;

    scanf("%lu", &n);

    unsigned long length = 1;

    for(unsigned long i = 0; i < n; i++) { length = length * 2 + 1; }

    char* string = alloca(length + 1);

    string[length];
    string[0] = 'a';

    unsigned long index = 1;

    for(unsigned long i = 1; i < n; i++)
    {
        string[index] = 'a';
        for(unsigned long j = 0; j < index; j++) { string[j]++; }
        memcpy(string + index + 1, string, index);

        index = index * 2 + 1;
    }

    printf("%s", string);
}

#pragma GCC diagnostic pop