有一个测试是错的,其他是对的,这是为什么;

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

I_want_to_change @ 2020-03-29 20:09:40

#include <stdio.h>
#include <stdlib.h>
int main()
{
    float a;
    scanf("%f", &a);
    int b = (int)(a);
    int c = (a - b) * 10;
    int d = b % 10;//个位
    int f = b / 10 % 10;//十位
    int e = b / 100;//百位
    printf("%.3f",c+d*0.1+f*0.01+e*0.001);
    return 0;
}

by 金庆涵 @ 2020-03-29 20:13:21

简单的做法:输入字符串,再逆序输出


by liqingyang @ 2020-03-29 20:16:43

楼上@金庆涵 正解,代码:

#include<iostream>
#include<string>
using namespace std;
int main()
{
    string str;
    cin>>str;
    reverse(str.begin(),str.end());
    cout<<str<<endl;
    return 0; 
}

by SIXIANG32 @ 2020-03-29 20:24:47

@shenhao200307 string/char a[]它不香吗?


by I_want_to_change @ 2020-03-29 20:34:59

@金庆涵 谢谢


by 金庆涵 @ 2020-03-29 20:46:28

@shenhao200307 You are welcome.


by 百因必AC @ 2020-03-29 21:44:24

你知道字符串吗,骚年????


|