CSES - Datatähti 2016 alku - Results
Submission details
Task:Kirjat
Sender:hugo-hur
Submission time:2015-10-05 18:04:44 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp:22:2: error: stray '\303' in program
  unsigned int* uolevinJärjestys = new unsigned int[n];
  ^
input/code.cpp:22:2: error: stray '\244' in program
input/code.cpp:23:2: error: stray '\303' in program
  unsigned int* maijanJärjestys = new unsigned int[n];
  ^
input/code.cpp:23:2: error: stray '\244' in program
input/code.cpp:24:2: error: stray '\303' in program
  readToArray(n, uolevinJärjestys);
  ^
input/code.cpp:24:2: error: stray '\244' in program
input/code.cpp:25:2: error: stray '\303' in program
  readToArray(n, maijanJärjestys);
  ^
input/code.cpp:25:2: error: stray '\244' in program
input/code.cpp:32:3: error: stray '\303' in program
   while (x == uolevinJärjestys[i] || x == maijanJärjestys[i] || contains(num, n, x)){
   ^
input/code.cpp:32:3: error: stray '\244' in program
input/code.cpp:32:3: error: stray '\303' in program
input/code.cpp:32:3: error: stray '\244' in program
input/code.cpp:43:2: error: stray '\303' in program
  delete[] uolevinJärj...

Code

#include <iostream>
#include <string>
#include <stdio.h>
//using namespace std;
bool contains(unsigned int* ptr, unsigned int len, unsigned int num){
	for (unsigned int i = 0; i < len; i++){
		if (ptr[i] == num){
			return true;
		}
	}
	return false;
}
void readToArray(unsigned int n, unsigned int* ptr){
	for (unsigned int i = 0; i < n; i++){
		std::cin >> ptr[i];
	}
}
int main() {
	std::cin.sync_with_stdio(false);//Faster execution
	unsigned int n;
	std::cin >> n;
	unsigned int* uolevinJärjestys = new unsigned int[n];
	unsigned int* maijanJärjestys = new unsigned int[n];
	readToArray(n, uolevinJärjestys);
	readToArray(n, maijanJärjestys);

	unsigned int* num = new unsigned int[n];
	memset(num, 0, n*sizeof(unsigned int));
	//Etsi lukujono, joka on välillä 0<num[x]<n && num[x] != uolevinJärjestys[x] && num[x] != maijanJärjestys[x]
	for (unsigned int i = 0; i < n; i++){
		unsigned int x = 1;
		while (x == uolevinJärjestys[i] || x == maijanJärjestys[i] || contains(num, n, x)){
			x++;
		}
		num[i] = x;
	}
	//std::string out();
	for (unsigned int i = 0; i < n; i++){
		std::cout << num[i] << ' ';
	}
	//std::cout << out << std::endl;
	delete[] num;
	delete[] uolevinJärjestys;
	delete[] maijanJärjestys;
	return 0;
}