50分

P1307 [NOIP2011 普及组] 数字反转

ping_fan @ 2017-03-20 13:22:24

#include <stdio.h>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <time.h>
#include <sstream>
#include <cstring>
#include <string>
#include <list>
#include <algorithm>
using namespace std;
int main()
{
int x,y,d=0,e=0;
char a[999],c[999];
cin>>a;
if(a[0]=='0')
{
cout<<"0";
system("pause");
return 0;
}
if(a[0]=='-'&&a[1]=='0')
{
cout<<"0";
system("pause");
return 0;
}
int b=strlen(a);
for(x=b-1,y=0;x>=0;--x,++y)
{
if(a[x]>='0'&&a[x]<='9')
c[y]=a[x];
if(a[x]=='-')
d=1;
}
if(d==1)
{
cout<<"-";
d=0;
}
for(x=0;x<b;++x)
{
if(c[x]=='0'&&e==0)
d=1;
else
{
e=1;
cout<<c[x];
}
}
system("pause");
}

by niqinaidezengyeye @ 2017-03-22 14:05:29

#include<cstdio>
using namespace std;
char s[10];
int main(){
    int i;
    bool k=1;
    for(i=1;(s[i]=getchar())!='\n'&&s[i]!='EOF';i++);
    if (s[1]=='-'){
        printf("-");
        for(int j=1;j<i-1;j++){
            if(k&&(s[i-j]=='0')) continue;
            k=0;
            printf("%c",s[i-j]);
        }
    }
    else for(int j=1;j<=i;j++){
        if(k&&(s[i-j]=='0')) continue;
        k=0;
        printf("%c",s[i-j]);
    }
    return 0;
}

by shipeiqian @ 2022-11-20 11:10:05

9527考古


|