数据有点水
查看原帖
数据有点水
321860
qiutongxue楼主2021/1/6 10:44
#include <iostream>
#include <vector>
#include <cstring>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#define fi first
#define se second
#define INF 0x3f3f3f3f

using namespace std;

typedef long long LL;
typedef pair<int , char> PII;

int main()
{
    string s;
    cin >> s;
    
    int t = 0;
    if(s.front() == '-' || s.front() == '+') t = 1;
    
    while(s.back() == '0') s.pop_back();
    
    reverse(s.begin() + t , s.end());
    cout << s << endl;
}

这份代码如果输入是:-0,输出是:-,显然不对,应该输出-0才对,但是能ac

应该在第二个while那里加一个判断才对

while(s.size() > 1 + t && s.back() == '0') 	s.pop_back();
2021/1/6 10:44
加载中...