logo AlgoBeat OnlineJudge
登录 注册

[TopCoder2] Reverse 题解

作者: charly666  ·  发布于 2026-06-08 20:22:19  ·  最后修改于 2026-06-08 20:27:22
已通过
审核员:UnratedCheater 终将消亡 · 2026-06-08 20:27:22

F1

直接从字符串的最后一个字符一直输出到第一个。

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

F2

使用 reverse 可以将数组翻转。

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

暂无评论

登录 后即可评论。