50分求助

P1307 [NOIP2011 普及组] 数字反转

scratch_szc @ 2024-10-05 15:47:39

代码:


#include<bits/stdc++.h>
#define int long long
using namespace std;
//const int N= ;
signed main(){
//  freopen("test.in","r",stdin);
//  freopen("test.out","w",stdout);
    string s;
    cin>>s;
    if(s[0]=='-'){
        reverse(s.begin()+1,s.end());
        cout<<'-';
        int id=0;
        while(s[id++]=='0'){
        }
        for(int i=id+1;i<s.size();i++)cout<<s[i];
    }else{ 
        int id=-1;
        reverse(s.begin(),s.end());
        while(s[id++]=='0'){
        }
        for(int i=id;i<s.size();i++)cout<<s[i];
    }
    return 0;
}

by _luogu_huowenshuo_ @ 2024-10-05 15:49:02

#include<bits/stdc++.h>
using namespace std;
int s,n = 0;
int main()
{
    cin >> s;
    while(s) 
        n = n * 10 + s % 10,s /= 10;
    cout << n;
    return 0;
}

@scratch_szc


by dulonghan2013 @ 2024-10-05 15:50:56

把16行的id+1改成id


by scratch_szc @ 2024-10-05 15:51:51

@dulonghan2013 不行呀


by dulonghan2013 @ 2024-10-05 15:52:09

18行的id=-1改成id=1


by dulonghan2013 @ 2024-10-05 15:52:21

两个都改


by scratch_szc @ 2024-10-05 15:52:32

@_luoguhuowenshuo THX


by xingluchuan123 @ 2024-10-05 15:53:57

ZTo


|