CSES - Datatähti 2020 alku - Results
Submission details
Task:Merkkijonot
Sender:Aapeli
Submission time:2019-10-12 17:17:48 +0300
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'x etsisamat(char*, char)':
input/code.cpp:21:30: error: invalid conversion from 'void*' to 'int*' [-fpermissive]
     palautettava.lista=malloc(51*sizeof(int));
                        ~~~~~~^~~~~~~~~~~~~~~~
input/code.cpp:23:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0; i<strlen(sana); i++) {
                   ~^~~~~~~~~~~~~
input/code.cpp: In function 'int onkoharmoniset(char*, char*)':
input/code.cpp:38:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0; i<strlen(a); i++){
                   ~^~~~~~~~~~
input/code.cpp: In function 'int main()':
input/code.cpp:78:28: error: invalid conversion from 'void*' to 'char**' [-fpermissive]
     char** kokolista=malloc(maara*sizeof(char*));
                      ~~~~~~^~~~~~~~~~~~~~~~~~~~~
input/code.cpp:83:28: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
         kokolista[i]=...

Code

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

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

struct x{
    int* lista;
    int pituus;
};

struct x etsisamat(char* sana,char merkki){
   
    struct x palautettava;
    palautettava.lista=malloc(51*sizeof(int));
    palautettava.pituus=0;
    for (int i=0; i<strlen(sana); i++) {
        if (sana[i]==merkki){
            palautettava.lista[palautettava.pituus]=i;
            palautettava.pituus++;
        }
    }
    return palautettava;
}

int onkoharmoniset(char* a,char* b){
    if (strlen(a)!=strlen(b))
        return 0;
    char* c=a;
    char* d=b;
    
    for (int i=0; i<strlen(a); i++){
        struct x cee=etsisamat(c, c[i]);
        struct x dee=etsisamat(d, d[i]);
        
        if(c[i]!=0){
            if (memcmp(cee.lista, dee.lista, cee.pituus*sizeof(int))) {
                return 0;
            }
        }
    }
    
    
    
    return 1;
}

int onkosama(char** a, char** b){
    if (a[0][0]!=b[0][0]) {
        return 0;
    }
    int arvot=a[0][0];
    while(arvot>0){
        
    }
    if (arvot==0)
        return 1;
    else
        return 0;
}




int main(void){
   
    
    int maara;
    scanf("%i",&maara);
    int parit=0;
    
    char** kokolista=malloc(maara*sizeof(char*));
    
    
    //luetaan merkkijonot
    for (int i=0; i<maara; i++){
        kokolista[i]=malloc(51*sizeof(char));
        scanf("%s",kokolista[i]);
    }
    
    for (int i= 0; i<maara; i++) {
        for (int a=i+1; a<maara; a++) {
            if (onkoharmoniset(kokolista[i], kokolista[a]))
                parit++;
        }
    }
    printf("%i",parit);
    for (int i=0; i<maara; i++)
        free(kokolista[i]);
    free(kokolista);
}