WA求助!!!

P5705 【深基2.例7】数字反转

2023113367wsy @ 2023-08-31 17:00:31


#include<stdio.h>
int main()
{
    char ad[12345];
    int x = 0;
    while (scanf("%c",&ad[x])==1)
        {
        x+=1;
        }
    for(;x>=0;x--)
        {
        printf("%c",ad[x]);
        }
    return 0;
}

by One_JuRuo @ 2023-08-31 17:12:31

#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
    cin>>s;
    for(int i=s.size()-1;i>=0;--i) cout<<s[i];
    return 0;
}

by liu_le_chen @ 2023-08-31 17:13:15

@One_JuRuo 人家发的好像是C语言


by One_JuRuo @ 2023-08-31 17:13:28

@2023113367wsy

while里用scanf,应该这样用:

while(~scanf("%c",&a))

while(scanf("%c",&a)!=EOF)

by One_JuRuo @ 2023-08-31 17:13:53

@liulechen 是我唐突了


by louis666 @ 2023-08-31 17:14:17

az


by liu_le_chen @ 2023-08-31 17:15:47

@One_JuRuo 我也是看了头文件才知道的


by 2023113367wsy @ 2023-08-31 18:00:07

@One_JuRuo 大佬,你这两个我试了下,都是too short on line 1(我原来那个也是)


by One_JuRuo @ 2023-08-31 18:04:18

@2023113367wsy 改C++吧


|