算法训练 字符串逆序

xiaoxiao2021-03-01  60

  输入一个字符串,长度在100以内,按相反次序输出其中的所有字符。

样例输入

tsinghua

样例输出

auhgnist

 

/*#include<iostream> #include <stack> using namespace std; int main() { stack<char>q; char c; c = getchar(); while(c != '\n') { q.push(c); c = getchar(); } while(!q.empty()) { cout << q.top(); q.pop(); } // cout << endl; return 0 ; } */ #include <iostream> #include <string> using namespace std; int main() { string s; cin >> s; for(int i=s.length()-1; i>=0; i--) { cout << s[i]; } cout << endl; }

 

转载请注明原文地址: https://www.6miu.com/read-4549927.html

最新回复(0)