Advertisement
AdelKhalilov

Untitled

Jan 29th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.70 KB | None | 0 0
  1.  
  2. import java.io.*;
  3. import java.util.Locale;
  4. import java.util.StringTokenizer;
  5. import java.util.TreeSet;
  6.  
  7.  
  8. public class C {
  9. String filename = "";//filename here, System.in/out if no file
  10.  
  11. FastScanner in;
  12. PrintWriter out;
  13.  
  14.  
  15. void solve() {
  16. //your code here
  17. String s = in.next();
  18. int n = s.length();
  19. long w = 0;
  20. for (int i = 0; i < n; i++) {
  21. w += w * 10 + (long) (s.charAt(i) - '0');
  22. }
  23. TreeSet<Long> set = new TreeSet<>();
  24. set.add(w);
  25. long max = 1;
  26. long kek = 1;
  27. long u = 0;
  28. for (int i = 0; i < n - 1; i++) {
  29. u = u * 10 + 9;
  30. kek *= 9;
  31. }
  32. String cop = s;
  33. for (int i = 0; i < s.length(); i++) {
  34. char ch = s.charAt(i);
  35. max *= (long) (ch - '0');
  36. }
  37. long res = max;
  38. if (kek == res) {
  39. set.add(u);
  40. } else {
  41. if (kek > res) {
  42. set.clear();
  43. set.add(u);
  44. res = kek;
  45. }
  46. }
  47.  
  48.  
  49. for (int i = 0; i < n; i++) {
  50. char[] e = s.toCharArray();
  51. if (s.charAt(i) == '0') {
  52. for (int j = 0; j < i; j++) {
  53. e[j] = '0';
  54. }
  55. continue;
  56. }
  57. String f = "";
  58. for (int j = 0; j < n; j++) {
  59. f += e[j];
  60. }
  61. s = f;
  62. String t = s;
  63. int xex = 0;
  64. long new_ans = 0;
  65. long new_pr = 1;
  66. char[]m = s.toCharArray();
  67. m[i] = (char) ((int) m[i] - 1);
  68. for (int j = i + 1; j < n; j++) {
  69. m[j] = '9';
  70. }
  71. while (xex < n && m[xex] == '0') {
  72. xex++;
  73. }
  74. for (int j = xex; j < n; j++) {
  75. new_pr *= (long) (m[j] - '0');
  76. }
  77. for (int c = 0; c < m.length; c++) {
  78. new_ans = new_ans * 10 + (c - '0');
  79. }
  80. if (new_pr == res) {
  81. set.add(new_ans);
  82. } else {
  83. if (new_pr > res) {
  84. res = new_pr;
  85. set.clear();
  86.  
  87. set.add(new_ans);
  88. }
  89. }
  90. }
  91. out.println(set.size());
  92.  
  93. while (set.size() > 0) {
  94. long y = set.pollFirst();
  95. if (y == 0) {
  96. continue;
  97. }
  98.  
  99. out.print(y + " ");
  100. }
  101.  
  102.  
  103. }
  104.  
  105. void run() throws IOException {
  106. InputStream input = System.in;
  107. OutputStream output = System.out;
  108. try {
  109. File f = new File(filename + ".in");
  110. if (f.exists() && f.canRead()) {
  111. input = new FileInputStream(f);
  112. output = new FileOutputStream(filename + ".out");
  113. }
  114. } catch (IOException e) {
  115. }
  116. in = new FastScanner(input);
  117. out = new PrintWriter(new BufferedOutputStream(output));
  118. solve();
  119. in.close();
  120. out.close();
  121. }
  122.  
  123. public static void main(String[] args) throws IOException {
  124. Locale.setDefault(Locale.US);
  125. new C().run();
  126. }
  127.  
  128. class FastScanner implements Closeable {
  129. private BufferedReader br;
  130. private StringTokenizer tokenizer;
  131.  
  132. public FastScanner(InputStream stream) throws FileNotFoundException {
  133. br = new BufferedReader(new InputStreamReader(stream));
  134. }
  135.  
  136. public String next() {
  137. while (tokenizer == null || !tokenizer.hasMoreTokens()) {
  138. try {
  139. tokenizer = new StringTokenizer(br.readLine());
  140. } catch (IOException e) {
  141. throw new RuntimeException(e);
  142. }
  143. }
  144. return
  145. tokenizer.nextToken();
  146. }
  147.  
  148. public String nextLine() {
  149. if (tokenizer == null || !tokenizer.hasMoreTokens()) {
  150. try {
  151. return br.readLine();
  152. } catch (IOException e) {
  153. throw new RuntimeException(e);
  154. }
  155. }
  156. return tokenizer.nextToken("\n");
  157. }
  158.  
  159. public int nextInt() {
  160. return Integer.parseInt(next());
  161. }
  162.  
  163. public long nextLong() {
  164. return Long.parseLong(next());
  165. }
  166.  
  167. public double nextDouble() {
  168. return
  169. Double.parseDouble(next());
  170. }
  171.  
  172. @Override
  173. public void close() throws IOException {
  174. br.close();
  175. }
  176. }
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement