「CJOJ2574」Lucky Transformati
Sample Input
7 2
2343223
4 1
2234
Sample Output
2243233
2334
题解
这是一道找规律题,发现233->223->233->223...此时就可以写出正解.
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout);
using namespace std;
inline int gi(){
int f=1,sum=0;char ch=getchar();
while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0' && ch<='9'){sum=sum*10+ch-'0';ch=getchar();}
return f*sum;
}
const int maxn=1000000+10;
char s[maxn];
int main(){
int i,j,k,n,m;
while(scanf("%d %d\n",&n,&k)!=EOF){
scanf("%s",s);
int len=strlen(s);
for(i=0;i<len;i++){
if(!k)break;
if(s[i]=='2' && s[i+1]=='3'){
k--;
if((i+1)%2==1)s[i+1]='2';
else{
s[i]='3';
if(s[i-1]=='2'){
if(k%2)s[i]='2';
break;
}
}
}
}
puts(s);
}
return 0;
}