7-31 字符串循环左移 (20 分) C++

往字符串最末尾加前N个字符,然后从第N+1个字符开始输出到末尾

#include 
#include 
using namespace std;

int main()
{
	string word;
	unsigned int N;
	getline(cin, word);
	cin >> N;
	if (N == 0) {
		cout << word << endl;
	}
	else {
		int length = word.size();
		for (int i = 0; i < N; ++i) {
			word.append(word, 0, N);
		}
		for (int j = N; j < length + N; ++j) {
			cout << word[j]; 
		}
		cout << endl;
	}

	return 0;
}

你可能感兴趣的:(PTA练习)