80分求助

P1307 [NOIP2011 普及组] 数字反转

shiffack @ 2024-08-14 09:05:15

#include <bits/stdc++.h>
using namespace std;
int b,c,d,e,f,g,h,j,k,l,m,n,i,x;
char a[20];
int main()
{
    cin.getline(a,20);
    for(int i=strlen(a)-1;i>=0;i--)
    {
        b=a[i];
        if(a[0]=='-'&&i==strlen(a)-1&&c==0)
        {
            cout<<'-';
            c=1;
        }
        if((b=='0'&&i==strlen(a)-1)||a[i]=='-')
        {

        }
        else cout<<a[i];
    }
    return 0;
}

by fire_flies @ 2024-08-14 09:07:35

@zhizhenwangshengdi 布什哥们,咋这么多变量


by shiffack @ 2024-08-14 09:08:17

@fire_flies 怕不够用


by zhizhenyaohanyu @ 2024-08-14 09:09:07

怎么发代码


by fire_flies @ 2024-08-14 09:09:36

@zhizhenwangshengdi 是re还是wa


by zhizhenyaohanyu @ 2024-08-14 09:10:03

@fire_flies 怎么发代码


by shiffack @ 2024-08-14 09:10:50

@fire_flies ? 听不懂


by fire_flies @ 2024-08-14 09:11:16

@zhizhenyaohanyu 编辑回复倒数第六个,选cpp


by zhizhenyaohanyu @ 2024-08-14 09:12:45

@fire_flies 哪个


by fire_flies @ 2024-08-14 09:13:18

@zhizhenyaohanyu 他会有提示


by zhizhenyaohanyu @ 2024-08-14 09:16:36

@zhizhenwangshengdi 可以这样做

#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,d,u,t;
char c;
cin>>a;
if(a>=1&&a<10){
cout<<a%10; 
}
else if(a>=10&&a<100){
cout<<a%10*10+a/10;
}
else if(a>=100&&a<1000){
cout<<a%10*100+a%100/10*10+a/100;
}
else if(a>=1000&&a<10000){
cout<<a%10*1000+a%100/10*100+a%1000/100*10+a/1000;
}
else if(a>=10000&&a<100000){
cout<<a%10*10000+a%100/10*1000+a%1000/100*100+a%10000/1000*10+a/10000;
}
else if(a>=100000&&a<1000000){
cout<<a%10*100000+a%100/10*10000+a%1000/100*1000+a%10000/1000*100+a%100000/10000*10+a/100000;
}
else if(a>=1000000&&a<10000000){
cout<<a%10*1000000+a%100/10*100000+a%1000/100*10000+a%10000/1000*1000+a%100000/10000*100+a%1000000/100000*10+a/1000000;
}
else if(a>=10000000&&a<100000000){
cout<<a%10*10000000+a%100/10*1000000+a%1000/100*100000+a%10000/1000*10000+a%100000/10000*1000+a%1000000/100000*100+a%10000000/1000000*10+a/10000000;
}
else if(a>=100000000&&a<1000000000){
cout<<a%10*100000000+a%100/10*10000000+a%1000/100*1000000+a%10000/1000*100000+a%100000/10000*10000+a%1000000/100000*1000+a%10000000/1000000*100+a%100000000/10000000*10+a/100000000;
}
else if(a==1000000000){
cout<<"1";
}
else if(a==0){
cout<<"0";
}
else if(a<=-1&&a>-10){
cout<<a%10; 
}
else if(a<=-10&&a>-100){
cout<<a%10*10+a/10;
}
else if(a<=-100&&a>-1000){
cout<<a%10*100+a%100/10*10+a/100;
}
else if(a<=-1000&&a>-10000){
cout<<a%10*1000+a%100/10*100+a%1000/100*10+a/1000;
}
else if(a<=-10000&&a>-100000){
cout<<a%10*10000+a%100/10*1000+a%1000/100*100+a%10000/1000*10+a/10000;
}
else if(a<=-100000&&a>-1000000){
cout<<a%10*100000+a%100/10*10000+a%1000/100*1000+a%10000/1000*100+a%100000/10000*10+a/100000;
}
else if(a<=-1000000&&a>-10000000){
cout<<a%10*1000000+a%100/10*100000+a%1000/100*10000+a%10000/1000*1000+a%100000/10000*100+a%1000000/100000*10+a/1000000;
}
else if(a<=-10000000&&a>-100000000){
cout<<a%10*10000000+a%100/10*1000000+a%1000/100*100000+a%10000/1000*10000+a%100000/10000*1000+a%1000000/100000*100+a%10000000/1000000*10+a/10000000;
}
else if(a<=-100000000&&a>-1000000000){
cout<<a%10*100000000+a%100/10*10000000+a%1000/100*1000000+a%10000/1000*100000+a%100000/10000*10000+a%1000000/100000*1000+a%10000000/1000000*100+a%100000000/10000000*10+a/100000000;
}
else if(a==-1000000000){
cout<<"1";
}

}

| 下一页