Simple Exercises--move! move!! Move!!!

Source: Internet
Author: User
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 ***********************************************************
 *****/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.