You are given an integer xx of nn digits a1,a2,…,ana1,a2,…,an, which make up its decimal notation in order from left to right.
Also, you are given a positive integer k<nk<n.
Let‘s call integer b1,b2,…,bmb1,b2,…,bm beautiful if bi=bi+kbi=bi+k for each ii, such that 1≤i≤m−k1≤i≤m−k.
You need to find the smallest beautiful integer yy, such that y≥xy≥x.
The first line of input contains two integers n,,k (2≤n≤200000,1≤k<n2≤n≤200000,1≤k<n): the number of digits in xx and kk.
The next line of input contains nn digits a1,a2,…,ana1,a2,…,an (a1≠0a1≠0, 0≤ai≤90≤ai≤9): digits of xx.
In the first line print one integer mm: the number of digits in yy.
In the next line print mm digits b1,b2,…,bmb1,b2,…,bm (b1≠0b1≠0, 0≤bi≤90≤bi≤9): digits of yy.
Examples
3 2 353
output
3 353
题意:就是给你一个长度为n的大小为十进制数x,且满足Xi=Xi+k(1≤i≤m−k.),要你找一个大小等于y的数,其中y>=x,也要满足Yi=Yi+k(1≤i≤m−k.)。
#include<bits/stdc++.h> using namespace std; char x[200005]; char y[200005]; int main(void) { int a,k; scanf("%d %d",&a,&k); cin>>x; for(int i=0;i<a;i++){//直接模拟 y[i]=x[i%k]; } if(strcmp(y,x)>=0)//y>=x { cout<<strlen(y)<<endl; cout<<y; return 0; } y[k-1]++; //如果有进位 int i=k-1; while(y[i]>=‘9‘+1) { y[i]=‘0‘; i--; y[i]++;//进位 } cout<<strlen(y)<<endl; for(int i=0;i<a;i++) y[i]=y[i%k]; cout<<y; return 0; }
codeforces-C. Long Beautiful Integer(字符串处理)
原文:https://www.cnblogs.com/xuanmaiboy/p/12105242.html