答案一直是对的可是提交不上去

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

LVTwoQinCai @ 2022-10-09 11:52:36

这是为啥呀明明所有自己输入的都可以正常反向

#include <iostream>
#include <string>
using namespace std;

int main() {
    string  a;
    cin >> a;
    for (int i = a.length(); i >= 0; i--) {
        cout << a[i];
    }
    cout << endl;

    return 0;
}

by jnyz2021109122116 @ 2022-10-09 11:56:00

@LVTwoQinCai 字符串从0位置开始存储,所以要从长度-1开始

for (int i = a.length()-1; i >= 0; i--) 

by jnyz2021109122116 @ 2022-10-09 11:58:50

学会阅读错误信息

read(ASCII 0)说明前面输出了一个空字符


by CodingID @ 2022-10-09 12:07:49

@LVTwoQinCai 有必要这么麻烦吗?


by SZH0523 @ 2022-10-09 12:22:00

@LVTwoQinCai

#include<bits/stdc++.h>
using namespace std;
signed 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 LVTwoQinCai @ 2022-10-09 12:23:08

@jnyz2021109122116 好的感谢大佬


|