Why is WA?

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

44i11 @ 2023-01-10 14:59:23

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

by Enoch006 @ 2023-01-10 15:14:32

您把getline换成cin试试?


by Enoch006 @ 2023-01-10 15:15:07

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

就像这样子


by _8008008 @ 2023-01-10 15:16:08

@0627Xx 没有return 0?(我不太确定)
不过我的写法和你差不多

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

by dyc2013 @ 2023-01-12 20:12:06

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

成为

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

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

|