救救孩子

P1307 [NOIP2011 普及组] 数字反转

ikun_jntm @ 2023-06-17 18:47:07

#include<iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main(){
char s[1001];
    cin>>s;
    if(s[0]=='-'){
        for(int i=strlen(a)-1;i>=0;i--){
        if(a[1]!=0){
            cout<<a[i];
}
return 0;
}
else{
    for(int i=strlen(a)-1;i>0;i--){
    if(a[1]!='0')cout<<a[i];
    }
    } 

}
    return 0;
}

by rnf5114 @ 2023-06-17 19:01:50

@ikun_jntm 上面的s怎么就变成a了还有正数情况仍然要i>=0然后是a[strlen(a)-1]!=0,如果输入的数字就是0应该怎么办


by zhouzihe @ 2023-06-17 19:15:18

@ikun_jntm

#include<bits/stdc++.h>
using namespace std;
long long int n,a=0;
int main(){
    cin>>n;
    if(n<0){
        cout<<"-";
        n=-n;
    }
    while(n!=0){
        a=a*10+n%10;
        n/=10;
    }
    cout<<a;
}

求关


by ikun_jntm @ 2023-06-17 20:24:29

@zhouzihe 谢谢大佬,我真的太蒟蒻了


by ikun_jntm @ 2023-06-17 20:24:56

@zhouzihe 已关注


by ikun_jntm @ 2023-06-17 20:25:16

@liyong5114 谢谢大佬,我真的太蒟蒻了


|