CSES - Datatähti 2016 alku - Results
Submission details
Task:Kirjat
Sender:Hoxy
Submission time:2015-10-01 14:26:55 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main(int, char**)':
input/code.cpp:17:38: error: 'memset' was not declared in this scope
  memset(inuse, -1, amount*sizeof(int));
                                      ^

Code

#include <iostream>

using namespace std;

int SeuraavaVapaa(int i, int i2, int* inuse, int amount);

int main(int argc, char *argv[]) {

	ios_base::sync_with_stdio(0);

	int amount = 0;
	cin >> amount;
	int* uolevi = new int[amount];
	int* maija = new int[amount];
	int* kaaleppi = new int[amount];
	int* inuse = new int[amount];
	memset(inuse, -1, amount*sizeof(int));
	for(int i = 0; i < amount; i++)
		cin >> uolevi[i];
	for(int i = 0; i < amount; i++)
		cin >> maija[i];

	for(int i = 0; i < amount; i++) {

		int next = SeuraavaVapaa(uolevi[i], maija[i], inuse, amount);
		kaaleppi[i] = next;
		inuse[next] = i;
	}

	for(int i = 0; i < amount; i++) {

		cout << kaaleppi[i] << " ";
	}

	return 0;
}

int SeuraavaVapaa(int i, int i2, int* inuse, int amount) {

	for(int i3 = 0; i3 < amount; i3++) {
		if(i3 == i || i3 == i2) continue;

		if(inuse[i3] == -1)
			return i3;
	}

	return -1;
}