CSES - Datatähti 2017 alku - Results
Submission details
Task:Bittijono
Sender:mika
Submission time:2016-10-03 19:19:17 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'std::string flip(std::string)':
input/code.cpp:9:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < s.length(); i++)
                               ^
input/code.cpp: In function 'char hankiBitti(int)':
input/code.cpp:22:16: error: 'size' was not declared in this scope
  while(size(out) < paikka)
                ^
input/code.cpp: In function 'int main()':
input/code.cpp:44:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < n.size(); i++)
                             ^

Code

#include <iostream>
#include <vector>
#include <string>
using namespace std;

string flip(string s)
{
	string out = "";
	for (int i = 0; i < s.length(); i++)
	{
		if (s[i] == '0')
			out += '1';
		if (s[i] == '1')
			out += '0';
	}
	return out;
}

char hankiBitti(int paikka)
{
	string out = "0";
	while(size(out) < paikka)
	{
		out += flip(out);
	}
	return out[paikka - 1];
}

int main()
{
	int count;
	cin >> count;

	vector<int> n;

	while (count > 0)
	{
		int num;
		cin >> num;
		n.push_back(num);
		count--;
	}

	for (int i = 0; i < n.size(); i++)
	{
		cout << hankiBitti(n[i]) << endl;
	}

	return 0;
}