zoukankan      html  css  js  c++  java
  • 「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,&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;
    }
    
    
  • 相关阅读:
    【20170923】2017暑假北京学习 day 3
    Leetcode 39
    事无巨细 | 访问一个网站的过程
    Leetcode 77
    排序 | 快速排序
    排序 | 堆排序
    Leetcode 60
    Leetcode 51
    海量数据处理的解法
    Leetcode 99
  • 原文地址:https://www.cnblogs.com/cjgjh/p/9360350.html
Copyright © 2011-2022 走看看