为什么有5个WA啊?

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

star_sink @ 2024-05-13 15:23:00


#include<iostream>
using namespace std;
int main(){
   float a,m;
   int b,c,d,e,f,g,h;
   cin>>a;
   b=a*10;
   c=b/1000;
   d=b%1000;
   e=d/100;
   f=d%100;
   g=f/10;
   h=f%10;
   m=(h*1000+g*100+e*10+c)*0.1;
   cout<<m<<endl;
   return 0;
}

by Chu_awa_xing @ 2024-05-13 16:25:59

@star_sink 这道题不用这么麻烦,直接用字符串string,然后获取长度倒着输出就行了


by Andy_Shen @ 2024-05-16 19:26:59

@star_sink 他只是3位数,一位小数

AC代码:

#include <bits/stdc++.h>
using namespace std;
int main(){
    char a, b, c, d;
    scanf("%c%c%c.%c", &a, &b, &c, &d);
    printf("%c.%c%c%c", d, c, b, a);
    return 0;
}

by star_sink @ 2024-05-17 10:14:50

@Chu_awa_xing @Andy_Shen 感谢大佬给的建议


|