字符串左移

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值