Code Submission Evaluation System Login

Datatähti 2016 alku

Start:2015-09-28 00:00:00
End:2015-10-12 00:00:00
 

Tasks | Scoreboard | Statistics


CSES - Datatähti 2016 alku - Results
History
2015-10-01 20:49:06100
2015-10-01 20:33:2643
2015-10-01 20:33:05
2015-10-01 20:28:4243
2015-10-01 20:24:2343
2015-10-01 19:37:0743
2015-10-01 19:19:4143
2015-10-01 19:01:290
2015-10-01 18:54:520
2015-10-01 18:30:5743
2015-10-01 18:10:340
Task:Kirjat
Sender:nagrodus
Submission time:2015-10-01 20:33:05
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;
}