Guest User

Untitled

a guest
Feb 21st, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.83 KB | None | 0 0
  1. import java.awt.Point;
  2. import java.io.*;
  3. import java.math.BigInteger;
  4. import java.security.KeyStore.Builder;
  5. import java.util.*;
  6.  
  7. import static java.lang.Math.*;
  8.  
  9. public class Testt {
  10.  
  11.     final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
  12.     BufferedReader in;
  13.     PrintWriter out;
  14.     StringTokenizer tok = new StringTokenizer("");
  15.  
  16.     void init() throws FileNotFoundException {
  17.         if (ONLINE_JUDGE) {
  18.             in = new BufferedReader(new InputStreamReader(System.in));
  19.             out = new PrintWriter(System.out);
  20.         } else {
  21.             in = new BufferedReader(new FileReader("input.txt"));
  22.             out = new PrintWriter("output.txt");
  23.         }
  24.     }
  25.  
  26.     String readString() throws IOException {
  27.         while (!tok.hasMoreTokens()) {
  28.             tok = new StringTokenizer(in.readLine());
  29.         }
  30.         return tok.nextToken();
  31.     }
  32.  
  33.     int readInt() throws IOException {
  34.         return Integer.parseInt(readString());
  35.     }
  36.  
  37.     long readLong() throws IOException {
  38.         return Long.parseLong(readString());
  39.     }
  40.  
  41.     double readDouble() throws IOException {
  42.         return Double.parseDouble(readString());
  43.     }
  44.  
  45.     public static void main(String[] args) {
  46.         new Testt().run();
  47.     }
  48.  
  49.     public void run() {
  50.         try {
  51.             long t1 = System.currentTimeMillis();
  52.             init();
  53.             solve();
  54.             out.close();
  55.             long t2 = System.currentTimeMillis();
  56.             System.err.println("Time = " + (t2 - t1));
  57.         } catch (Exception e) {
  58.             e.printStackTrace(System.err);
  59.             System.exit(-1);
  60.         }
  61.     }
  62.  
  63.     boolean f(long x) {
  64.         while (x > 0) {
  65.             long y = x % 10;
  66.             if (y != 4 && y != 7) {
  67.                 return false;
  68.             }
  69.             x /= 10;
  70.         }
  71.         return true;
  72.     }
  73.  
  74.     // solve! good luck :)
  75.     public void solve() throws IOException {
  76.         int n = readInt();
  77.         int k = readInt();
  78.         n++;
  79.         String s = readString();
  80.         char[] c = new char[s.length() + 1];
  81.         for (int i = 1; i < n; i++) {
  82.             c[i] = s.charAt(i - 1);
  83.         }
  84.         String t = "444";
  85.         String l = "477";
  86.         s = "";
  87.         a: while (true) {
  88.             for (int i = 1; i < n; i++) {
  89.                 s += c[i];
  90.                 if (s.equals("47") || s.equals("447") || s.equals("477")) {
  91.                     if (s.equals("47")) {
  92.                         if ((i - 1) % 2 == 0) {
  93.                             c[i - 1] = '7';
  94.                             k--;
  95.                         } else {
  96.                             c[i] = '4';
  97.                             k--;
  98.                         }
  99.                     }
  100.                     if (s.equals("477")) {
  101.                         if ((i - 2) % 2 == 0) {
  102.                             k--;
  103.                         } else {
  104.                             if (k % 2 != 0) {
  105.                                 c[i - 1] = '4';
  106.                                 break a;
  107.                             } else {
  108.                                 if (k % 2 == 0) {
  109.                                     break a;
  110.                                 }
  111.                             }
  112.                         }
  113.                     }
  114.                     if (s.equals("447")) {
  115.                         if ((i - 2) % 2 == 0) {
  116.                             k--;
  117.                         } else {
  118.                             if (k % 2 != 0) {  
  119.                                 c[i - 1] = '7';
  120.                                 break a;
  121.                             } else {
  122.                                 if (k % 2 == 0) {
  123.                                     break a;
  124.                                 }
  125.                             }
  126.                         }
  127.  
  128.                     }
  129.                 }
  130.                 if (!s.equals("4") ||  (!s.equals("47")) || (!s.equals("44"))){ s="";};
  131.             }
  132.             break a;
  133.         }
  134.         for (int i = 1; i < n; i++) {
  135.             out.print(c[i]);
  136.         }
  137.     }
  138. }
Add Comment
Please, Sign In to add comment