Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Point;
- import java.io.*;
- import java.math.BigInteger;
- import java.security.KeyStore.Builder;
- import java.util.*;
- import static java.lang.Math.*;
- public class Testt {
- final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
- BufferedReader in;
- PrintWriter out;
- StringTokenizer tok = new StringTokenizer("");
- void init() throws FileNotFoundException {
- if (ONLINE_JUDGE) {
- in = new BufferedReader(new InputStreamReader(System.in));
- out = new PrintWriter(System.out);
- } else {
- in = new BufferedReader(new FileReader("input.txt"));
- out = new PrintWriter("output.txt");
- }
- }
- String readString() throws IOException {
- while (!tok.hasMoreTokens()) {
- tok = new StringTokenizer(in.readLine());
- }
- return tok.nextToken();
- }
- int readInt() throws IOException {
- return Integer.parseInt(readString());
- }
- long readLong() throws IOException {
- return Long.parseLong(readString());
- }
- double readDouble() throws IOException {
- return Double.parseDouble(readString());
- }
- public static void main(String[] args) {
- new Testt().run();
- }
- public void run() {
- try {
- long t1 = System.currentTimeMillis();
- init();
- solve();
- out.close();
- long t2 = System.currentTimeMillis();
- System.err.println("Time = " + (t2 - t1));
- } catch (Exception e) {
- e.printStackTrace(System.err);
- System.exit(-1);
- }
- }
- boolean f(long x) {
- while (x > 0) {
- long y = x % 10;
- if (y != 4 && y != 7) {
- return false;
- }
- x /= 10;
- }
- return true;
- }
- // solve! good luck :)
- public void solve() throws IOException {
- int n = readInt();
- int k = readInt();
- n++;
- String s = readString();
- char[] c = new char[s.length() + 1];
- for (int i = 1; i < n; i++) {
- c[i] = s.charAt(i - 1);
- }
- String t = "444";
- String l = "477";
- s = "";
- a: while (true) {
- for (int i = 1; i < n; i++) {
- s += c[i];
- if (s.equals("47") || s.equals("447") || s.equals("477")) {
- if (s.equals("47")) {
- if ((i - 1) % 2 == 0) {
- c[i - 1] = '7';
- k--;
- } else {
- c[i] = '4';
- k--;
- }
- }
- if (s.equals("477")) {
- if ((i - 2) % 2 == 0) {
- k--;
- } else {
- if (k % 2 != 0) {
- c[i - 1] = '4';
- break a;
- } else {
- if (k % 2 == 0) {
- break a;
- }
- }
- }
- }
- if (s.equals("447")) {
- if ((i - 2) % 2 == 0) {
- k--;
- } else {
- if (k % 2 != 0) {
- c[i - 1] = '7';
- break a;
- } else {
- if (k % 2 == 0) {
- break a;
- }
- }
- }
- }
- }
- if (!s.equals("4") || (!s.equals("47")) || (!s.equals("44"))){ s="";};
- }
- break a;
- }
- for (int i = 1; i < n; i++) {
- out.print(c[i]);
- }
- }
- }
Add Comment
Please, Sign In to add comment