string70pts,任务一#7#9#10WA和任务2WA

P1307 [NOIP2011 普及组] 数字反转

mediocre_ @ 2022-08-17 20:33:07

#include<bits/stdc++.h>
using namespace std;
int main() {
    string a;
    cin>>a;
    int sum = 0;
    if (a[0] == '-'){
        printf("-");
        sum++;
    }
    for (int i = a.size() - 1;i >= sum;--i){
        if (a[i] != '0'){
            cout<<a[i];
        }
    }
    return 0;
}

by mediocre_ @ 2022-08-17 20:44:03

已AC,代码:

#include<bits/stdc++.h>
using namespace std;
int main() {
    string a;
    cin>>a;
    int sum = 0;
    if (a.size() == 1){
        cout<<a[0];
        return 0;
    }
    if (a[0] == '-'){
        printf("-");
        sum++;
    }
    int kley = 0;
    for (int i = a.size() - 1;i >= sum;--i){
        if (a[i] != '0' || kley >= 1){
            cout<<a[i];
            kley++;
        }
    }
    return 0;
}

by xiazexuan @ 2022-08-17 20:50:13

那你还发什么??不怕被抄??


|