Advertisement
AdelKhalilov

Untitled

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