#include <iostream> using namespace std; // 输入一个字符串(包括英文和中文),将其反序输出, 如: // hello 今天真热 ---> 热真天今 olleh int numChar(char c) // English -> 1 C -> n C -> 0 { int n = 0; for (int i=7; i>=0; i--) { if (c & (1<<i)) { n++; } else { break; } } if (n == 0) { return 1; } else if (n == 1) { return 0; } else { return n; } } int main() { string a; string b; getline(cin, a); int n = a.size(); b.resize(n); for (int i=0; i<n; ) { int len = numChar(a[i]); if (len == 0) { i++; continue; } for (int j=0; j<len; j++) { b[n-i-len+j] = a[i+j]; // a[0] a[1]------ a[n-1] // b[n-1]b[n-2]------b[0] } i += len; } cout << "a = " << a << endl; cout << "b = " << b << endl; }