大佬们,请问一下为什么是五个WA

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

GREATchen @ 2023-10-29 14:57:42

```cpp

include<iostream>

using namespace std;

int main() { double a; cin>>a; a*=10;

 int n=10;
 int b[n];
for(int i=0;i<4;i++)
{

    b[i]=(int)a%10;

    a/=10.0;
}

double square=0.0;
square=b[0]*100+b[1]*10+b[2]*1+(double)(b[3]*0.1);
cout<<square;

}


by Vsinger_洛天依 @ 2023-10-29 15:02:55

所以你的md怎么这么奇怪


by cly312 @ 2023-10-29 15:05:48

用得着这么繁?

#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 Vsinger_洛天依 @ 2023-10-29 15:06:22

字符串秒了


by 初星逝者 @ 2023-10-29 15:39:24

?

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

by Vincent615 @ 2023-10-29 15:42:26

很简单

string + reverse


by wzh_45 @ 2023-11-04 08:46:57

直接用字符串存就行了:

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

by wzh_45 @ 2023-11-04 08:55:01

@Vincent615

reverse

函数代码:

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

by Vincent615 @ 2023-11-05 12:54:53

@wzh_45

是的,没错


|