0分求助!
查看原帖
0分求助!
582601
Been_Drunk楼主2022/8/27 10:40

如题,只有RE和WA,请各位dalao帮忙看看。

#include <bits/stdc++.h>
using namespace std;
stack <char> a;
char c[1005];
char ans[1005];
int i = 1;
int main()
{
	while (scanf("%c", &c[i]) ==1)
	{
		i++;
	}
	if (c[1] == 0)
	{
		cout << 0;
	}
	if (c[1] == '-')
	{
		ans[1] = '-';
		for (int j = 2; j < i; j++)
		{
			a.push(c[j]);
			if (a.top() == '0' && c[j + 1] == '0' || a.top() == '0' && c[j + 1] != '0')
			{
				a.pop();
			}
		}
		for (int j = 2; j < i; j++)
		{
			ans[j] = a.top();
			a.pop();
		}
	}
	else
	{
		for (int j = 1; j <= i; j++)
		{
			a.push(c[j]);
			if (a.top() == '0' && c[j + 1] == '0' || a.top() == '0' && c[j + 1] != '0')
			{
				a.pop();
			}
		}
		for (int j = 1; j <= i; j++)
		{
			ans[j] = a.top();
			a.pop();
		}
	}
	for (int j = 1; j <= i; j++)
	{
		printf("%c", ans[j]);
	}
	return 0;
}
2022/8/27 10:40
加载中...