题解 CF1189A 【Keanu Reeves】

很容易理解一道题目,分类讨论即可:

  • 如果本身就是好序列,直接输出 11 与本身字符串。

  • 如果不是,输出 22 并且输出该字符串的第一个(或者最后一个)字符然后空格,接着是后面的。

代码:

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

int main()
{
	ios::sync_with_stdio(false);
	string s;
	cin >> s >> s;
	int cnt1 = count(s.begin(), s.end(), '1'), cnt0 = count(s.begin(), s.end(), '0');
	if (cnt1 != cnt0)
	{
		cout << "1\n" << s << endl;
	}
	else
	{
		cout << "2\n";
		cout << s[0] << " ";
		s.erase(s.begin());
		cout << s << endl;
	}
	//system("pause");
	return 0;
}
posted @ 2021-01-27 21:41  HappyBobb  阅读(10)  评论(0)    收藏  举报  来源