3AC,只会笨方法了求大佬看看哪里错了

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

zhengfly @ 2024-10-08 23:40:58

#include <stdio.h>

int main()
{
    int a,b,c,d;
    float x;
    scanf("%f",&x);
    a=x/100;
    ;b=(x-a*100)/10;
    ;c=(x-a*100-b*10)/1;
    ;d=(x-a*100-b*10-c)*10;
    printf("%.3f",1*d+0.1*c+0.01*b+0.001*a);
    return 0;
}

by Lisuyang @ 2024-10-09 00:18:30

@AAA159635

函数背的多就是好用

#include <bits/stdc++.h>
using namespace std;
string k;
int main(){
    cin >> k;
    reverse(k.begin(), k.end());
    cout << k;
    return 0;
}

by 杜都督 @ 2024-10-09 00:33:38

@AAA159635

d = int(x * 10) % 10;

你原来的代码更容易产生精度损失


|