牛客网 - 在线编程 - 华为机试 - 字符逆序

题目描述

将一个字符串str的内容颠倒过来,并输出。str的长度不超过100个字符。 如:输入“I am a student”,输出“tneduts a ma I”。 
输入参数:

inputString:输入的字符串

返回值:

输出转换好的逆序字符串

输入描述:

输入一个字符串,可以有空格

输出描述:

输出逆序的字符串

示例1

输入

I am a student

输出

tneduts a ma I

C++:

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

int main()
{
    char str;
    while(getline(cin, str))
    {
        for(int i = str.size() - 1; i >= 0 ; i--)
        {
            cout << str[i] ;
        }
    }
    return 0;
}

Python:

print(input()[::-1])

猜你喜欢

转载自blog.csdn.net/qq_39735236/article/details/81773820