WA???

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

liyunxiao_ycy @ 2024-05-15 16:01:43

哪位巨佬能帮忙瞅瞅吗


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

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

by liyunxiao_ycy @ 2024-05-15 16:02:14

全WA


by LHM_zs @ 2024-05-15 16:15:00

@liyunxiao_ycy for循环i是n-1,不是n


by KRST_ @ 2024-05-15 16:15:33

@liyunxiao_ycy

code:

#include <cstdio>
using namespace std;
char a, b, c, d;
int main()
{
    scanf("%c%c%c.%c", &a, &b, &c, &d);
    printf("%c.%c%c%c", d, c, b, a);
    return 0;
}

by xhx2011 @ 2024-05-15 16:15:39

n-1啊 @liyunxiao_ycy


by XuYu0317 @ 2024-05-15 16:16:44

将第十行

for(int i = n;i >= 0;i--)

改为

for(int i = n-1;i >= 0;i--)

by caojinyu0518 @ 2024-07-11 19:57:02

@liyunxiao_ycy 用reverse不香吗


|