游客 Signup | Login
中文 | En

1676 - 搞破坏

某位大神闯进了ACM俱乐部的总部,打算搞一番破坏……他决定把桌面上的一份文件里面的每个单词都改一下。

他要把这个单词的前面k个字母移到单词的末尾去。

Input

输入有多组数据。

每组数据一行,包含一个单词(只有英文字母,长度<=2000),一个正整数k(小于单词长度)。

Output

对应每组数据,输出被破坏后的单词。

Examples

Input

clubACM 4
Butterfly 7

Output

ACMclub
lyButterf

Solution C

/*
 * =====================================================================================
 *
 *       Filename:  903.c
 *
 *    Description: hahahhaha 
 *
 *        Version:  1.0
 *        Created:  2013/9/3 星期二 15:11:22
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  mdk-vim.cpp-c (mdk), mengdaikun@gmail.com
 *        Company:  cjluacm-vim-mdk
 *
 * =====================================================================================
 */
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

#define MAX 2000

int main()
{
   // freopen("a.in","r",stdin);
    
    char str[MAX];

    int k;

    int i;

    int len;

    while(~scanf("%s %d",str,&k))
    {
        len = strlen(str);

        for(i = k ; i < len ; i++)
            printf("%c",str[i]);
        for(i = 0 ; i < k ; i++)
            printf("%c",str[i]);
        printf("\n");
    }

    return 0;
}

Solution C++

#include <stdio.h>
#include "string.h"


///////////////////////////////////////////////////////////////////////
// Reverse the string between pStart and pEnd
///////////////////////////////////////////////////////////////////////
void ReverseString(char* pStart, char* pEnd)
{
      if(pStart != NULL && pEnd != NULL)
      {
            while(pStart <= pEnd)
            {
                  char temp = *pStart;
                  *pStart = *pEnd;
                  *pEnd = temp;

                  pStart ++;
                  pEnd --;
            }
      }
}

///////////////////////////////////////////////////////////////////////
// Move the first n chars in a string to its end 
///////////////////////////////////////////////////////////////////////
char* LeftRotateString(char* pStr, unsigned int n)
{
      if(pStr != NULL)
      {
            int nLength = static_cast<int>(strlen(pStr));
            if(nLength > 0 && n > 0 && n < nLength)
            {
                  char* pFirstStart = pStr;
                  char* pFirstEnd = pStr + n - 1;
                  char* pSecondStart = pStr + n;
                  char* pSecondEnd = pStr + nLength - 1;

                  // reverse the first part of the string
                  ReverseString(pFirstStart, pFirstEnd);
                  // reverse the second part of the strint
                  ReverseString(pSecondStart, pSecondEnd);
                  // reverse the whole string
                  ReverseString(pFirstStart, pSecondEnd);
            }
      }

      return pStr;
}

int main()
{
	char s[9999];
	int n;
	while(scanf("%s%d",s,&n)!=EOF)
		printf("%s\n",LeftRotateString(s,n));
	return 0;
} 
Time Limit 1 second
Memory Limit 32 MB
Discuss Stats
上一题 下一题