CSES - Datatähti 2020 alku - Results
Submission details
Task:Ruudukko
Sender:Aapeli
Submission time:2019-10-08 22:27:10 +0300
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:14:21: error: invalid conversion from 'void*' to 'int*' [-fpermissive]
     int* list=malloc(number*sizeof(int));
               ~~~~~~^~~~~~~~~~~~~~~~~~~~
input/code.cpp:27:35: error: invalid conversion from 'void*' to 'int*' [-fpermissive]
                 int*newlist=malloc(number*sizeof(int));
                             ~~~~~~^~~~~~~~~~~~~~~~~~~~
input/code.cpp:61:31: error: invalid conversion from 'void*' to 'int*' [-fpermissive]
             int*newlist=malloc(number*sizeof(int));
                         ~~~~~~^~~~~~~~~~~~~~~~~~~~
input/code.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i",&number);
     ~~~~~^~~~~~~~~~~~~~

Code

//
//  sudoku.c
//  datatahti
//
//  Created by aapo haavisto on 10/6/19.
//  Copyright © 2019 Aapo Haavisto. All rights reserved.
//

#include <stdio.h>
#include <stdlib.h>
int main (void){
    int number;
    scanf("%i",&number);
    int* list=malloc(number*sizeof(int));
    for (int e=0;e<=number;e++){
        list[e]=e+1;
    }
        
    
    if (number%2==0) {
   
        
        
            for (int i=0; i<number; i++) {
                for (int a=0; a<number; a++){
                }
                int*newlist=malloc(number*sizeof(int));
            
                for (int a=0;a<number;a++){
                    printf("%i",list[a]);
                    printf(" ");
                if ((list[a])%2==1){
                    if(a==number-1){
                        newlist[0]=list[a];
                    }
                    
                else{
                    newlist[a+1]=list[a];
                }
                }
               
                else{
                    if(a==0){
                        newlist[number-1]=list[a];
                    }
                    else{
                        newlist[a-1]=list[a];
                    }
                }
                }
             
             printf("\n");
                list=newlist;
        }
    }
    
    else{
        for (int i=0; i<number; i++) {
            for (int a=0; a<number; a++){
            }
            int*newlist=malloc(number*sizeof(int));
            
            for (int a=0;a<number;a++){
                printf("%i",list[a]);
                printf(" ");
                    if(a==0){
                        newlist[number-1]=list[a];
                    }
                    else{
                        newlist[a-1]=list[a];
                    }
            }
            
            printf("\n");
            list=newlist;
        }
    }
    free(list);

}