CSES - Datatähti 2016 alku - Results
Submission details
Task:Bittipeli
Sender:while(false)
Submission time:2015-10-11 23:58:01 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'std::string search(std::vector<int>)':
input/code.cpp:46:22: error: invalid use of member function (did you forget the '()' ?)
    if (i == c.size - 1) {
                      ^

Code

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

vector<int> v;
string input;

string search(vector<int> a);

int main() {
	int s = -1;
	string a, b = " ";
	getline(cin, input);
	for (int i = 0; i < (int)input.size(); i++) {
		a = input.substr(i, 1);
		if (a == b) {
			v[s]++;
		}
		else {
			v.push_back(1);
			s++;
		}
		b = a;
	}

	string d = search(v);
	if (d == "") {
		cout << "QAQ";
	}
	else {
		cout << ((int)d.size() / 2 + 1) << "\n";
		cout << d;
	}
	return 0;
}

string search(vector<int> a) {
	int b = 1;
	for (int i = 0; i < (int)a.size(); i++) {
		if (a[i] != 1) {
			vector<int> c = a;
			if (c.size() == 1 && c[0]>1) {
				return "1";
			}
			if (i == c.size - 1) {
				c.pop_back();
			}
			if (i > 0) {
				c[i - 1] += c[i + 1];
				for (int j = i + 2; j < (int)c.size(); j++) {
					c[j - 2] = c[j];
				}
				c.pop_back();
				c.pop_back();
			}
			else {
				for (int j = i + 1; j < (int)c.size(); j++) {
					c[j - 1] = c[j];
				}
				c.pop_back();
			}
			string r = search(c);
			if (r != "") {
				return to_string(b).append(" ").append(r);
			}
			b++;
		}
	}
	return "";
}