为啥是80分啊!!!!

P1307 [NOIP2011 普及组] 数字反转

chengchenghao @ 2019-09-25 14:45:58

#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdio>
#include<cmath>

using namespace std;
string n,l;
int main()
{

  cin>>n;
  if(n[0]=='-')
  cout<<'-';
  for(int i=n.size()-1;i>=0;i--)
  {
    if(i==n.size()-1&&n[i]=='0'||i==0&&n[i]=='-'||n[i]<48||n[i]>57)
    l='0';
    else cout<<n[i];
  }

  return 0;
}

by my_load @ 2019-09-25 14:51:12

前导0不一定只有一个呢

还有,

&&和||之间要加括号哦


by 斗神_君莫笑 @ 2019-09-25 14:53:33

@chengchenghao &&和||的运算符优先级要注意


by chengchenghao @ 2019-09-25 15:00:24

谢谢dalao


by xxx听取AC声一片 @ 2019-10-27 20:49:26

#include<stdio.h>
void turnover(int i, char a[],int k){
    int t=0;
        while(a[i]=='0'){
            i--;
        }
        for(;i>=k;i--){
            printf("%c",a[i]);
            t=1;
        }
        if(t==0){
            printf("0");
        }

}

int main(){
    char num[22];
    int i,j;
    int a=0;
    scanf("%s",num);
    if(num[0]=='-'){
        printf("-");
        for(i=0;i<21;i++){
            num[i]=num[i+1];
        }
    }
    for(i=0;i<22;i++){
         if(num[i]=='\0'){
            i--;
            break;
        }
    }

    turnover(i,num,0);

    return 0;
} 

|