75pts,#4#10#13#14#15WA,求调
查看原帖
75pts,#4#10#13#14#15WA,求调
521554
W1ngD1nGa5ter楼主2025/1/7 21:03

rt,不知道又哪个坑没注意,球球dalao们救救蒟蒻吧! (对了,不要纠结错误流输出,评测机不判)

#include <bits/stdc++.h>
using namespace std;
string msg, ans;
int number;
inline void FakeCode(string Cause = "NO REASON")
{
	cout << "Error\n";
	cerr << "BECAUSE " << Cause << endl;
	exit(EXIT_SUCCESS);
}
inline int toi(string s, int start = 3)
{
	int x = 0;
	for (int i = start; i < 8; ++i)
		x = x * 2 + s[i] - '0';
	return x;
}
inline string tos(int x)
{
	if (x == 0)
		return "0";
	string s;
	while (x)
		s += (x % 10) + '0', x /= 10;
	return s;
}
int main()
{
	cin >> msg;
	auto len = msg.length();
	if (len % 8)
		FakeCode("The message must be able to be cut into 8-character pieces.");
	for (char i : msg)
		if (i != '0' && i != '1')
			FakeCode("The message must be composed of '0' and '1'.");
	for (int i = 0; i < len / 8; ++i)
	{
		string now = msg.substr(8 * i, 8);
		cerr << now << ": ";
		if (msg[8 * i] == '1')
			if (msg[8 * i + 2] == '0')
				FakeCode("A unit cannot start with '100' or '110'.");
			else if (msg[8 * i + 1] == '0')
				if (toi(now) >= 26)
					FakeCode("The number is too big to turn to a upper letter.");
				else
					ans += toi(now) + 'A';
			else
				ans += ' ';
		else if ((++i) * 8 <= len && msg[8 * i] == '0')
			ans += tos(toi(now, 1) / 2 + toi(msg.substr(8 * i, 8), 1) / 2);
		else
			FakeCode("No more unit for the number to add.");
		cerr << "[" << ans << "]\n";
	}
	cout << ans << endl;
	return 0;
}
2025/1/7 21:03
加载中...