求调,样例全过,爆RE,悬关
查看原帖
求调,样例全过,爆RE,悬关
1007495
xiaoyiteng楼主2024/3/8 17:55
#include <bits/stdc++.h>
using namespace std;
string s, xs;
stack<char> ms;
int main()
{
	cin >> s;
	for (int i = 0; i < s.size(); i++)
	{
		char c = s[i];
		if (c == 'C')
		{
			if(ms.size() >= 2 && ms.top() == 'B')
			{
				ms.pop();
				if (ms.top() == 'A')
					ms.pop();
				else
				{
					ms.push('B');
					ms.push('C');
				}
			}
			else
				ms.push('C');
		}
		else
		{
			ms.push(c);
		}
	}
	int len = ms.size();
	for (int i = 0; i < len; i++)
	{
		xs[len-i] = ms.top();
//		cout << ms.top();
		ms.pop();
	}
	for (int i = 1; i <= len; i++)
		cout << xs[i];
	return 0;
 } 
2024/3/8 17:55
加载中...