0分求助!

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

wanyuanshenma @ 2022-07-11 09:25:51

蒟蒻求助


by little_cindy @ 2022-07-11 09:29:05

@wanyuanshenma 代码?


by Wei_Yue @ 2022-07-11 09:29:37

主页双贴splm


by wanyuanshenma @ 2022-07-11 09:31:26

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

by Greenzhe @ 2022-07-11 09:33:02

for(int i=strlen(a);i>=0;i--){

应为

for(int i=strlen(a)-1;i>=0;i--){

by wanyuanshenma @ 2022-07-11 09:34:34

@chuxuanzhe 谢谢


by little_cindy @ 2022-07-11 09:36:41

@wanyuanshenma 显然 a[strlen(a)] 是一个空的值吧,循环改成for(int i=strlen(a)-1;i>=0;i--){


by weather_forecast @ 2022-07-14 17:34:42

我用的拼接 float a,s,d,f,g; cin>>a; s=int(a10)/1000; d=int(a10)/100%10; f=int(a10)/10%10; g=int(a10)%10; cout<<g<<"."<<f<<d<<s;


by Jiaxiaoyuan11 @ 2022-07-18 14:41:54

@wanyuanshenma 你在循环时应该是 (i=strlen(a)-1)
还有,我建议你输入用

cin.getline(a,100);


by Ryanhao @ 2022-08-16 14:53:55

试试这个:

#include <bits/stdc++.h>
using namespace std;

int main() {
    string s;
    cin >>s;
    for (int i = s.size()-1; i >= 0; i--) {
        cout << s[i];
    }
    system("pause");
    return 0;
}

ac程序


|