Advertisement
Guest User

Untitled

a guest
May 19th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.46 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6.  
  7. public class Main {
  8.  
  9.     public static void main(String[] args) {
  10.         contest3();
  11.     }
  12.  
  13.     public static void contest3() {
  14.  
  15.         try {
  16.  
  17.             byte[] buf = new byte[10];
  18.             int index = -1;
  19.             int v;
  20.             while ((v = System.in.read()) != 10 && v != 13) {
  21.                 buf[++index] = (byte) v;
  22.             }
  23.             if (v == 13) System.in.read(); // if CR LF used, read LF
  24.  
  25.             byte[] numberBytes = new byte[index + 1];
  26.             System.arraycopy(buf, 0, numberBytes, 0, index + 1);
  27.             int size = Integer.parseInt(new String(numberBytes));
  28.             if (size == 0) return;
  29.  
  30.  
  31.             char[] previousMass = {'!'};  // Что точто не повторялось
  32.            
  33.             StringBuilder stringBuilder = new StringBuilder();
  34.            
  35.             for (int i = 0; i < size; i++) {
  36.  
  37.                 char[] tmpCurrentMass = new char[32];
  38.                 int currentMassIndex = 0;
  39.  
  40.  
  41.                 while (true) {
  42.                     int currentByte;
  43.                     if ((currentByte = System.in.read()) >= '!' && currentByte <= '}') {
  44.                         tmpCurrentMass[currentMassIndex] = (char) currentByte;
  45.                         currentMassIndex++;
  46.                     } else break;
  47.                 }
  48.  
  49.                 char[] currentMass = new char[currentMassIndex];
  50.  
  51.                 System.arraycopy(tmpCurrentMass, 0, currentMass, 0, currentMassIndex);
  52.  
  53.                 if (currentMass.length == previousMass.length) {
  54.                     boolean isContinue = false;
  55.  
  56.                     for (int i1 = 0; i1 < currentMass.length; i1++) {
  57.                         if (currentMass[i1] != previousMass[i1])
  58.                             isContinue = true;
  59.                     }
  60.                     if (!isContinue) continue;
  61.                 }
  62.  
  63.                 previousMass = currentMass;
  64.                 for (int i1 = 0; i1 < currentMass.length; i1++) {
  65.                     stringBuilder.append(currentMass[i1]);
  66.                 }
  67.                 stringBuilder.append('\n');
  68.  
  69.                 if (i % 250 == 0) System.gc();
  70.  
  71.             }
  72.            
  73.             System.out.print(stringBuilder.toString());
  74.            
  75.         } catch (IOException e) {
  76.             e.printStackTrace();
  77.         }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement