字符串左移

1218: 字符串左移

时间限制: 1 Sec  内存限制: 2 MB
提交: 27  解决: 10

题目描述

给一个长度等于N的字符串,求它左移M位后的字符串。

输入

每组数据两行,第一行N M, 0<N<=1000,0<=M<=1500

第二行给出字符串,字符串只包含大小写字母。

输出

输出左移后的结果。

样例输入

6 3
NetCan
6 2
NetCan
10 4
HelloWorld
 

样例输出

CanNet
tCanNe
oWorldHell
 
一开始没注意M的范围大于N
 
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
    int len,n,i;
    char a[1001];
    while(~scanf("%d%d",&len,&n))
    {
        n=n%len;
        scanf("%s",a);
        for(i=n;i<len;i++)
            printf("%c",a[i]);
        for(i=0;i<n;i++)
            printf("%c",a[i]);
        cout<<endl;
    }
}
原文地址:https://www.cnblogs.com/a1225234/p/4676590.html