Guest User

Untitled

a guest
Jun 14th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. public class Main {
  5. public static void main(String[] args) throws Exception {
  6. PrintWriter out = new PrintWriter(System.out);
  7. FastScanner in = new FastScanner(System.in);
  8. Question ob = new Question();
  9. ob.solve(in, out);
  10. out.close();
  11. }
  12.  
  13. static class Question {
  14. int[] freq, req;
  15.  
  16. public void solve(FastScanner in, PrintWriter out) {
  17. int[] days = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  18.  
  19. String s = in.next();
  20. freq = new int[10];
  21. req = new int[10];
  22. for (int i = 0; i < s.length(); i += 2) freq[s.charAt(i) - 48]++;
  23.  
  24. // for (int i : freq) out.print(i + " ");
  25.  
  26. for (int m = 12; m >= 1; --m) {
  27. for (int d = days[m]; d >= 1; --d) {
  28. for (int h = 23; h >= 0; --h) {
  29. for (int mi = 59; mi >= 0; --mi) {
  30. req[fi(m)]++;
  31. req[se(m)]++;
  32.  
  33. req[fi(d)]++;
  34. req[se(d)]++;
  35.  
  36. req[fi(h)]++;
  37. req[se(h)]++;
  38.  
  39. req[fi(mi)]++;
  40. req[se(mi)]++;
  41.  
  42. if (valid()) {
  43. out.print("" + fi(m) + se(m) + "/");
  44. out.print("" + fi(d) + se(d) + " ");
  45. out.print("" + fi(h) + se(h) + ":");
  46. out.print("" + fi(mi) + se(mi));
  47. return;
  48. }
  49. Arrays.fill(req, 0);
  50. }
  51. }
  52. }
  53. }
  54. out.println(0);
  55. }
  56.  
  57. private boolean valid() {
  58. for (int i = 0; i < 10; ++i) {
  59. if (freq[i] < req[i]) return false;
  60. }
  61. return true;
  62. }
  63.  
  64. private int fi(int x) { return x/10; }
  65.  
  66. private int se(int x) { return x%10; }
  67. }
  68. }
  69.  
  70. class FastScanner
  71. {
  72. private InputStream stream;
  73. private byte[] buf = new byte[1024];
  74. private int curChar;
  75. private int numChars;
  76.  
  77. public FastScanner(InputStream stream)
  78. {
  79. this.stream = stream;
  80. }
  81.  
  82. int read()
  83. {
  84. if (numChars == -1)
  85. throw new InputMismatchException();
  86. if (curChar >= numChars)
  87. {
  88. curChar = 0;
  89. try
  90. {
  91. numChars = stream.read(buf);
  92. }
  93. catch (IOException e)
  94. {
  95. throw new InputMismatchException();
  96. }
  97.  
  98. if (numChars <= 0)
  99. return -1;
  100. }
  101. return buf[curChar++];
  102. }
  103.  
  104. boolean isSpaceChar(int c)
  105. {
  106. return c==' '||c=='\n'||c=='\r'||c=='\t'||c==-1;
  107. }
  108.  
  109. boolean isEndline(int c)
  110. {
  111. return c=='\n'||c=='\r'||c==-1;
  112. }
  113.  
  114. int nextInt()
  115. {
  116. return Integer.parseInt(next());
  117. }
  118.  
  119. long nextLong()
  120. {
  121. return Long.parseLong(next());
  122. }
  123.  
  124. double nextDouble()
  125. {
  126. return Double.parseDouble(next());
  127. }
  128.  
  129. String next()
  130. {
  131. int c = read();
  132. while (isSpaceChar(c))
  133. c = read();
  134. StringBuilder res = new StringBuilder();
  135. do
  136. {
  137. res.appendCodePoint(c);
  138. c = read();
  139. } while(!isSpaceChar(c));
  140. return res.toString();
  141. }
  142.  
  143. String nextLine()
  144. {
  145. int c = read();
  146. while (isEndline(c))
  147. c = read();
  148.  
  149. StringBuilder res = new StringBuilder();
  150. do
  151. {
  152. res.appendCodePoint(c);
  153. c = read();
  154. } while(!isEndline(c));
  155. return res.toString();
  156. }
  157. }
Add Comment
Please, Sign In to add comment