将一个字符串str的内容颠倒过来,并输出。
数据范围:
# coding: utf-8 def func(s): #思路:一看到逆序,就要想到用栈 stack = [] for i in s: stack.append(i) new_queue = [] while stack: node = stack.pop() new_queue.append(node) print ''.join(new_queue) if __name__ == "__main__": import sys line1 = sys.stdin.readline().strip() func(line1)
input = input() length = len(input) for i in range(length): print(input[length-1-i],end='')
#!/usr/bin/env python # -*- coding:utf-8 -*- #@Time : 2020/9/8 10:50 #@Author: bz #@File : 字符逆序.py while True: try: s = input() print(s[::-1]) except: break
import sys for s in sys.stdin: a = list(s.strip()) n = int(len(a)/2) m = len(a) for i in range(n): k = a[i] a[i] = a[m-1-i] a[m-1-i] = k print("".join(a))