Topic Description:In assembly language There is a shift instruction called cyclic left-shift (ROL), now has a simple task, is to use strings to simulate the operation of this instruction results. For a given sequence of characters s, ask you to shift its loop left K-bit after the sequence output. For example, the character sequence s= "Abcxyzdef", requiring the output loop to move left 3 digits after the result, namely "XYZDEFABC". is not very simple. OK, take care of it.
Input:Multiple sets of test data, each containing a character sequence s and a nonnegative integer k. The length of which s is not more than 1000.
Output:corresponding to each test case, output a new sequence.
Sample Input:
Udboj 4
ABBA 1
Sample output:
Judbo
Bbaa
Summary: The topic is very simple, pay attention to start k%=n; inertia is easy to ignore
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include < string> #include <map> #include <cmath> #include <assert.h> #include <vector> #include <
Limits.h> using namespace std;
Char strdic[1005]; void Reverse (char* str, int start, int end) {while (start<end) {Char temp = s
Tr[start];
Str[start] = Str[end];
Str[end] = temp;
start++;
end--;
int main () {//freopen ("In.txt", "R", stdin);
int k;
while (cin>>strdic>>k) {int Len=strlen (strdic);
K%=len;
Reverse (strdic,0,k-1);
Reverse (strdic,k,len-1);
Reverse (strdic,0,len-1);
cout<<strdic<<endl;
return 0; }/************************************************************** problem:1362 User:xjbscut LanguagE:c++ result:accepted time:350 Ms memory:1512 KB ***********************************************************
*****/