蒟蒻90分求助

P1307 [NOIP2011 普及组] 数字反转

liumeihao @ 2023-10-05 19:07:22

#include<bits/stdc++.h>
using namespace std;
const int N=1e6+101;
using ll=long long;
#define int long long
signed main(){
    std::ios::sync_with_stdio(0),cin.tie(0);
    string s;
    cin>>s;
    int f=0,t;
    if(s[0]=='-'){
        s.erase(0,1);
        f=1;
    }
    for(int i=0;i<s.size();i++){
        if(s[i]>='1'&&s[i]<='9')
            t=i;
    }
    for(int i=t;i<s.size();i++){
        if(s[i]=='0')
            s.erase(i,i+1);
    }
    reverse(s.begin(),s.end());
    if(f)cout<<'-';
    cout<<s;
    return 0;
}

by AceKnightPuppet @ 2023-10-11 19:52:05

#include <bits/stdc++.h>
using namespace std;
int main(){
      //  freopen("isbn.in", "r", stdin);
     //   freopen("isbn.out", "w", stdout);
     int n,s;
            cin>>n;
    while(n) s=s*10+n%10,n/=10;
    cout<<s;
    //fclose(stdin);
    //fclose(stdout);
    return 0;
}

|