循环移位(基础题)

3088. 循环移位

单点时限: 2.0 sec

内存限制: 256 MB

输入两个正整数 n (保证不会以 0 开头)和 m,输出 n 的位数以及 n 经过循环右移 m 位后的数 (两者以一个空格分隔) 。

例如:

输入:1 1,输出:1 1

输入:123 2,输出:3 231

输入:1001234 5,输出:7 123410

输入:2100012345 55,输出:10 1234521000

输入格式

输入 2 个正整数 n 和 m, 两个数之间用一个空格分隔。

输出格式

在一行中输出 n 的位数以及 n 经过循环右移 m 位后的数,两者之间用一个空格分隔。

样例

input
2100012345 55
output
10 1234521000


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
int ans[10000000];
int main()
{
     string n;
     int m;
     cin>>n>>m;
     int len=n.length();
     cout<<len<<" ";
     m=m%len;
     for(int i=0;i<len;i++)
         ans[(i+m)%len]=n[i]-48;
     int st=0;
    for(int i=0;i<len;i++)  
        if(ans[i]==0) st++;
            else break;
    for(int i=st;i<len;i++) printf("%d",ans[i]); 
    return 0;
}

 

posted @ 2021-09-03 13:29  寒方  阅读(134)  评论(0编辑  收藏  举报