CSES - Datatähti 2016 alku - Results
Submission details
Task:Kirjat
Sender:nagrodus
Submission time:2015-10-01 20:33:05 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main(int, char**)':
input/code.cpp:27:4: error: 'needSwap' was not declared in this scope
    needSwap = true;
    ^
input/code.cpp:39:4: error: 'needSwap' was not declared in this scope
    needSwap = true;
    ^

Code

#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(int argc, char* argv[])
{
	ios_base::sync_with_stdio(0);
	int n,i;
	cin >> n;
	int *s1 = new int[n];
	int *s2 = new int[n];
	int *finished = new int[n];
	for (i = 0; i < n; i++){
		cin >> s1[i];
		finished[i] = i;
		s1[i]--;
	}
	for (i = 0; i < n; i++){
		cin >> s2[i];
		s2[i]--;
	}
	for (int i = 0; i < n; i++){
		if (finished[i] == s1[i] || finished[i] == s2[i]){
			needSwap = true;
			for (int j = i + 1; j < n; j++){
				if ((finished[j] != s1[i] && finished[j] != s2[i]) && (finished[i] != s1[j] && finished[i] != s2[j])){
					needSwap = false;
					swap(finished[i], finished[j]);
					break;
				}
			}
		}
	}
	for (int i = n - 1; i >= 0; i--){
		if (finished[i] == s1[i] || finished[i] == s2[i]){
			needSwap = true;
			for (int j = i - 1; j >= 0; j--){
				if ((finished[j] != s1[i] && finished[j] != s2[i]) && (finished[i] != s1[j] && finished[i] != s2[j])){
					needSwap = false;
					swap(finished[i], finished[j]);
					break;
				}
			}
		}
	}
	for (int i = 0; i < n - 1; i++)
		printf("%d ", finished[i]+1);
	printf("%d", finished[n - 1]+1);
	delete[] s1;
	delete[] s2;
	delete[] finished;
	return 0;
}