HDU 1020 Encoding 字符串

主要的字符串处理转换。

喷一喷HDU这个超级垃圾的推断系统:假设把数字存入字符串数组中输出就会错误。

如:A2B3C。假设当中的2和3保存如字符串数组中。然后输出那么就推断为WA,必须是即时输出数字2和3才算正确。

这样判我WA,哎。 HDU做好点你们的推断系统吧。

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

int main()
{
	int T;
	string s;
	scanf("%d", &T);
	while (T--)
	{
		cin>>s;
		int c = 1;
		char a = s[0];
		for (unsigned i = 1; i < s.size(); i++)
		{
			if (a == s[i]) c++;
			else
			{
				if (c > 1) cout<<c;//測试这样输出为错误cout<<char(c+'0');实际应该为正确。推断系统垃圾。

cout<<a; c = 1; a = s[i]; } } if (c > 1) cout<<c; cout<<a<<endl; } return 0; }




原文地址:https://www.cnblogs.com/wgwyanfs/p/7045335.html