跳到正文

科技·工程

P5705

#SUSPENDED#约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 1 分钟

版本

  1. v1当前

这一题如果你老老实实用变量做,身为小白的你会炸的. 所以这一题是练习字符串的好机会! string :

C++
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s1;
/*c++面相对象(class)的字符串,包含在string头文件中(iostream也包含了)*/
    cin>>s1;
/*s1.size()使用来获取字符串长度的,等价于s1.lenth()*/
    for(int i=s1.size()-1;i>=0;i--){
        cout<<s1[i];
    }
    return 0;
}

C风格(字符数组)

C++
#include<bits/stdc++.h>
using namespace std;
int lenth(char *a){
    char *p=a;
    int cnt=0;
    while(*p){
        cnt++;
        p++;
    }
    return cnt;
}
int main(){
    char s[1000];
    scanf("%s",s);
    for(int i=strlen(s)-1;i>=0;i--){
        printf("%c",s[i]);
    }
}
原文