華為-字串反轉

reignsdu發表於2018-07-17

題目連結

https://www.nowcoder.com/practice/e45e078701ab4e4cb49393ae30f1bb04?tpId=37&tqId=21235&tPage=1&rp=&ru=/ta/huawei&qru=/ta/huawei/question-ranking

題目描述

寫出一個程式,接受一個字串,然後輸出該字串反轉後的字串。例如:

輸入描述:

輸入N個字元

輸出描述:

輸出該字串反轉後的字串

示例1

輸入

複製

abcd

輸出

複製

dcba

題解:

#include <iostream>
#include <string>
using namespace std;
int main(){
  string s;
  cin >> s;
  int l = s.length();
  for(int i = 0; i < l; i++){
    cout << s[l - i - 1];
  }
  return 0;
}


 

相關文章