CSES - Datatähti 2016 alku - Results
Submission details
Task:Kirjat
Sender:KARHU
Submission time:2015-10-07 12:11:19
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:120:28: error: cannot pass objects of non-trivially-copyable type 'std::basic_stringstream<char>::__string_type {aka class std::basic_string<char>}' through '...'
     printf("%s\n", ss.str());
                            ^

Code

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

#include <iostream>
#include <sstream>

int main()
{
    int i, j, n;
    int *uolevi, *maija, *kaaleppi;

    if(fscanf(stdin, "%d", &n) > 0)
    {
        uolevi = (int*)malloc(n * sizeof(int));
        for(i = 0; i < n; ++i)
            if(fscanf(stdin, "%d", &uolevi[i]) < 0)
                break;

        maija = (int*)malloc(n * sizeof(int));
        for(i = 0; i < n; ++i)
            if(fscanf(stdin, "%d", &maija[i]) < 0)
                break;

        kaaleppi = (int*)malloc(n * sizeof(int));
        memset(kaaleppi, 0, n * sizeof(int));
    } else
        return 1;

    for(i = 0; i < n; ++i)
    {
        for(j = 0; j < n; ++j)
        {
            if(kaaleppi[j] == 0 && uolevi[j] != (i + 1) && maija[j] != (i + 1))
            {
                kaaleppi[j] = (i + 1);
                break;
            }
        }
    }

    for(i = 0; i < n; ++i)
    {
        if(kaaleppi[i] == uolevi[i] || kaaleppi[i] == maija[i] || kaaleppi[i] == 0)
        {
            memset(kaaleppi, 0, n * sizeof(int));
            goto kaanna1;
        }
    }

    goto valmis;

kaanna1:
    for(i = n; i > 0; --i)
    {
        for(j = 0; j < n; ++j)
        {
            if(kaaleppi[j] == 0 && uolevi[j] != i && maija[j] != i)
            {
                kaaleppi[j] = i;
                break;
            }
        }
    }

    for(i = 0; i < n; ++i)
    {
        if(kaaleppi[i] == uolevi[i] || kaaleppi[i] == maija[i] || kaaleppi[i] == 0)
        {
            memset(kaaleppi, 0, n * sizeof(int));
            goto kaanna2;
        }
    }

    goto valmis;

kaanna2:
    for(i = 0; i < n; ++i)
    {
        for(j = n; j > 0; --j)
        {
            if(kaaleppi[j - 1] == 0 && uolevi[j - 1] != (i + 1) && maija[j - 1] != (i + 1))
            {
                kaaleppi[j - 1] = (i + 1);
                break;
            }
        }
    }

    for(i = 0; i < n; ++i)
    {
        if(kaaleppi[i] == uolevi[i] || kaaleppi[i] == maija[i] || kaaleppi[i] == 0)
        {
            memset(kaaleppi, 0, n * sizeof(int));
            goto kaanna3;
        }
    }

    goto valmis;

kaanna3:
    for(i = n; i > 0; --i)
    {
        for(j = n; j > 0; --j)
        {
            if(kaaleppi[j - 1] == 0 && uolevi[j - 1] != i && maija[j - 1] != i)
            {
                kaaleppi[j - 1] = i;
                break;
            }
        }
    }

valmis:
    std::stringstream ss;

    for(i = 0; i < n; ++i)
        ss << kaaleppi[i] << " ";

    printf("%s\n", ss.str());

    free(uolevi);
    free(maija);
    free(kaaleppi);
    
    return 0;
}

/*
5 2 1 3 4
4 1 3 2 5

1     1 1
2   2   2
3 3     3
  4 4 4
  5 5 5

1 3 2 4 X (pienin ->)
3 5 4 1 2 (suurin ->)
X 3 2 4 1 (pienin <-)
X X 4 5 3 (suurin <-)
*/