求助!为什么无法通过/(ㄒoㄒ)/~~!测试样例代入是对的呀

P1307 [NOIP2011 普及组] 数字反转

m3o7o2n1 @ 2024-02-06 19:16:15

#include <stdio.h>
int main() {
    int y,sum,n;
    scanf("%d",&n);
    while(n!=0){
        y=n%10;
        sum=sum*10+y;
        n=n/10;
    }
    printf("%d",sum);
    return 0;
}

by DFs_YYDS @ 2024-02-06 19:29:32

@m3o7o2n1 把 sum 初始化为0


by DFs_YYDS @ 2024-02-06 19:30:53

@m3o7o2n1 试过了,可以AC


by Axolotl_awa @ 2024-02-06 19:33:04

@m3o7o2n1 你

sum

没初始化成0


by Axolotl_awa @ 2024-02-06 19:34:58

有的编译器会帮你把没初始化的初始化成0,但洛谷会给它一个随机值,


by Axolotl_awa @ 2024-02-06 19:36:20

还有你这题也太像题解了吧。。。


by m3o7o2n1 @ 2024-02-06 19:43:01

@DFs_YYDS 好的好的,太感谢了!!!/(ㄒoㄒ)/~~


by m3o7o2n1 @ 2024-02-06 19:43:56

@wuboyan714 好的好的明白了,太感谢了!!!இ௰இ


by m3o7o2n1 @ 2024-02-06 19:45:27

@wuboyan714 之前做过类似的数字反转题目,当时不会做就看题解记住了这种算法இ௰இ


by DFs_YYDS @ 2024-02-11 11:21:56

@m3o7o2n1 今天突然看到这个帖子,告诉你一个事情,你用0分的代码,把O2关了就能AC


by lunxiaotong0118 @ 2024-02-18 14:46:02

#include<bits/stdc++.h>
using namespace std;
int n,s=0;
int main()
{
    cin>>n;
    while(n) s=s*10+n%10,n/=10;
    cout<<s;
    return 0;
}

| 下一页