家人们,帮忙看看,没看出哪错了,但那都报错,求大佬帮忙救命!!!

P1307 [NOIP2011 普及组] 数字反转

linyiyi123456 @ 2023-03-01 01:29:58

#include<stdio.h>
#include<math.h>
int main()
{
    int a[100],m=0,i,sum=0,n;
    scanf("%d",&n);
    while(n>0)
    {
        a[m++]=n%10;
        n/=10;
    }
    int m1=m;
    for(i=0;i<m;i++)
    {
        if(a[1]==0)
        {
            m1--;
            continue;
        }
        else
        {
            sum+=a[i]*pow(10,m1-1);
            m1--; 
        }
        printf("%d",sum);
    }
    if(n<0)
    {
        printf("-%d",sum);
    }
    else
    {
        printf("%d",sum);
    }
    return 0;
}

by CCX_Ug @ 2023-03-01 08:28:21

标题党


by CCX_Ug @ 2023-03-01 08:30:12

如果n是负数的话那么前面的

while (n > 0)

就不会被执行


by CCX_Ug @ 2023-03-01 08:31:00

而且不建议用pow


by CCX_Ug @ 2023-03-01 08:33:18

AC记录


by linyiyi123456 @ 2023-03-03 01:46:18

#include<stdio.h>
#include<math.h>
int main()
{
    int a[10],m=0,i,sum=0,n,n1;
    scanf("%d",&n);
    if(n==0)
    {
        printf("0");
    }
    else
    {
        n1=abs(n);
        while(n1>0)
        {
            a[m++]=n1%10;
            n1/=10;
        }
        int m1=m;
        if(n<0)
        {
            printf("-");
        }
        for(i=0;i<m;i++)
        {

            if(a[i]==0)
            {
                if(a[i-1]==0)
                {
                    continue;
                }

            }
            else
            {
                printf("%d",a[i]);
            }
        }
    }

    return 0;
}

@the_player 麻烦大佬再帮我康康,7,9,10编译过不了


by CCX_Ug @ 2023-03-03 18:17:10

你这个交到你谷上不会CE

这里

if(a[i]==0)
{
    if(a[i-1]==0)
    {
        continue;
    }
}

遇到0就不会输出

其实我不是dalao


by CCX_Ug @ 2023-03-03 18:17:56

再改一改\~~


by linyiyi123456 @ 2023-03-04 00:22:57

@the_player 我这边0可以出


by zhangboyuan0 @ 2023-03-13 21:19:46

我这个是100

c++

#include <bits/stdc++.h>
using namespace std;
int main(){
    int num;
    cin >> num;
    if(num == 0){
        cout << 0;
        return 0;
    }
    if(num < 0){
        cout << '-';
        num = -num;
    }
    while(num % 10 == 0 && num > 0){
        num = num / 10;
    }
    while(num > 0){
        cout << num % 10;
        num = num / 10;
    }

    return 0;
}

|