http://zhedahht.blog.163.com/blog/static/2541117420073993725873/
#include <iostream> #include <cstring> using namespace std; void reverse_string(char *s, char *e) { if (s != nullptr && e != nullptr) { while (s < e) { char c = *e; *e = *s; *s = c; ++s, --e; } } } char* left_rotate_string(char *s, size_t n) { if (s != nullptr) { size_t len = static_cast<int>(strlen(s)); if (n > 0 && len > 0 && n < len) { reverse_string(s, s + n - 1); reverse_string(s + n, s + len - 1); reverse_string(s, s + len - 1); } } return s; } int main() { char b[200]; cin >> b; left_rotate_string(b, 2); cout << b; return 0; }