0分求助!!!

P1307 [NOIP2011 普及组] 数字反转

chen_17 @ 2024-12-01 21:19:06

#include<iostream>

using namespace std;

 int main()

{

  int a,b,c,n;

  cin>>a;
    if(a<0) 
    {
    a=-a;
    c=-1;
    }
    else c=1;
    while(a!=0)
    {
        n=a%10;
        a=a/10;
        b=b*10+n;
    }
    b=b*c;
    cout<<b;
    return 0;
}

by zmher @ 2024-12-01 21:26:25

主代码:

int n, a=0;
cin>>n;
while(n){
    a=a*10+n%10;
    n/=10;
}
cout<<a<<endl;

自行理解


by chen_17 @ 2024-12-02 16:11:56

@zmher感谢!


by zmher @ 2024-12-02 17:51:44

求互关


|