将一个字符串左移n位


#include
using namespace std;
void shiftone(string &s, int m)
{
	while (m--)
	{

		char t = s[0];
		int len = s.size();
		for (int i = 1; i < len; ++i)
			s[i - 1] = s[i];
		s[len - 1] = t;
	}
}


int main()
{
	int m = 0;
	string str;
	getline(cin, str);
	int n;
	cin >> n;
	shiftone(str, n);
	cout << str;
}

相关