Codeforces 122 D. Lucky Transformation (Regular) _ Common skills

Source: Internet
Author: User
Description

Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers, 744, 4 are lucky and 5, 467.

Petya has a number consisting of n digits without leading. He represented it as an array of digits without leading zeroes. Let ' s call it D. The numeration starts with 1, starting from the most significant digit. Petya wants to perform the following operation K Times:find the minimum x (1≤x < n) such that DX = 4 and dx + 1 = 7, If x is odd, then to assign dx = dx + 1 = 4, otherwise to assign dx = dx + 1 = 7. Note that if no x is found, then the operation counts as completed and the array doesn ' t change in all.

You are are given the initial number as an array of digits and the number K. Help Petya find the result of completing K Operat ions.

Input

The "I" contains two integers n and K (1≤n≤10^5, 0≤k≤10^9)-the number of digits in the number and the NUM ber of completed operations. The second line contains n digits without spaces representing the array of digits D, starting with D1. It is guaranteed that the digit of the number does not equal zero.

Output

In the "single" Print the result without spaces-the number after the K operations are fulfilled.

examples Input

7 4
4727447

examples Output

4427477

the

Given a string composed of 4, 7, each time from left to right to find the first 47, and then judge its starting subscript is even or odd, if the odd number, then replace with 44, otherwise replace with 77, the maximum operation K, to find the final result.

train of Thought

Obviously, replacing 47 with 44 will only have an effect on the current position, and replacing 77 will have an impact on the current position.

If the i−1 i-1 position in the string is also 4, you will find that 447 of this will produce a cycle, at this point can be directly to the results, otherwise traverse the original string to modify it.

AC Code

 #include <bits/stdc++.h> #define IO Ios::sync_with_stdio (false); \ cin.tie (0); \ cout.

Tie (0);
using namespace Std;
typedef long Long LL;

const int MAXN = 1E5+10;
int n,k;
Char A[MAXN];
    int main () {cin>>n>>k;
    GetChar ();
    Gets (a+1); for (int i=1; i<=n-1&&k; i++) {if (a[i]== ' 4 ' &&a[i+1]== ' 7 ') {if (i&1)
            A[I+1] = ' 4 ';
                    else {if (a[i-1]== ' 4 ') {if (k&1) a[i]= ' 7 ';
                    Else a[i]= ' 4 ';
                Break
            else a[i]= ' 7 ';
        }--k;
    } puts (a+1);
return 0; }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.