A8345 | Lucky Transformation
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya has a number consisting of $n$ digits without leading zeroes. 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 $d_{x}=4$ and $d_{x+1}=7$ , if $x$ is odd, then to assign $d_{x}=d_{x+1}=4$ , otherwise to assign $d_{x}=d_{x+1}=7$ . Note that if no $x$ was found, then the operation counts as completed and the array doesn't change at all.
You are given the initial number as an array of digits and the number $k$ . Help Petya find the result of completing $k$ operations.
Petya has a number consisting of $n$ digits without leading zeroes. 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 $d_{x}=4$ and $d_{x+1}=7$ , if $x$ is odd, then to assign $d_{x}=d_{x+1}=4$ , otherwise to assign $d_{x}=d_{x+1}=7$ . Note that if no $x$ was found, then the operation counts as completed and the array doesn't change at all.
You are given the initial number as an array of digits and the number $k$ . Help Petya find the result of completing $k$ operations.
输入格式
The first line contains two integers $n$ and $k$ $(1<=n<=10^{5},0<=k<=10^{9})$ — the number of digits in the number and the number of completed operations. The second line contains $n$ digits without spaces representing the array of digits $d$ , starting with $d_{1}$ . It is guaranteed that the first digit of the number does not equal zero.
输出格式
In the single line print the result without spaces — the number after the $k$ operations are fulfilled.
输入输出样例
输入 #1
7 4 4727447
输出 #1
4427477
输入 #2
4 2 4478
输出 #2
4478
In the first sample the number changes in the following sequence: $4727447→4427447→4427477→4427447→4427477$ .
In the second sample: $4478→4778→4478$ .
In the second sample: $4478→4778→4478$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted