马蜂良好,90分求助!qwq
查看原帖
马蜂良好,90分求助!qwq
1079073
Hatsunatsu楼主2023/11/4 11:17

RT,栈方法。感觉思路没有什么问题,但 WA#7。

评测记录

代码如下:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<cstring>
#include<cctype>

typedef long long ll;
typedef long double ld;

using namespace std;
const int MAXN=1000000005;

char a[MAXN],b[MAXN];
ll t;

void push(char n){
	a[t++]=n;
}

void pop(){
	t--;
}

char top(){
	return a[t-1];
}

int size(){
	return t;
}

bool empty(){
	return t==0;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin.getline(b,MAXN);
	ll i=0;
	ll res=0;
	if(b[0]=='0'&&b[1]=='\0'){
		cout<<0;
		return 0;
	}
	while(b[i]!='\0'){
		push(b[i]);
		if(top()=='0'&&i==0){
			pop();
		}
		else if(top()=='0'&&i==1){
			pop();
		}
		if(top()=='-'){
			pop();
			res=1;
		}
		i++;
	}
	while(top()=='0'){
		pop();
	}
	if(res==1){
		cout<<"-";
	}
	while(!empty()){
		cout<<top();
		pop();
	}
	return 0;
}
2023/11/4 11:17
加载中...