Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7. public static void main(String[] args) {
  8. Scanner scanner = new Scanner(System.in);
  9. int a, b, c, a2, b2, c2;
  10. a = scanner.nextInt();
  11. b = scanner.nextInt();
  12. c = scanner.nextInt();
  13. a2 = a;
  14. b2 = b;
  15. c2 = c;
  16. boolean done = false;
  17. String string = "";
  18. char aux = ' ';
  19. if (a > b && a > c) {
  20. while (a - 2 > (b + c) * 2) {
  21. a--;
  22. a2--;
  23. }
  24. }
  25. if (b > a && b > c) {
  26. while (b - 2 > (a + c) * 2) {
  27. b--;
  28. b2--;
  29. }
  30. }
  31. if (c > b && c > a) {
  32. while (c - 2 > (b + a) * 2) {
  33. c--;
  34. c2--;
  35. }
  36. }
  37. while (a != 0) {
  38. string = string + 'a';
  39. a--;
  40. }
  41. while (b != 0) {
  42. string = string + 'b';
  43. b--;
  44. }
  45. while (c != 0) {
  46. string = string + 'c';
  47. c--;
  48. }
  49. char[] array = new char[a2 + b2 + c2 + 5];
  50. for(int i = 2; i < a2 + b2 + c2 + 2; i++){
  51. array[i] = string.charAt(i - 2);
  52. }
  53. array[0] = ' ';
  54. array[1] = ' ';
  55. array[a2 + b2 + c2 + 3] = ' ';
  56. array[a2 + b2 + c2 + 4] = ' ';
  57. while(!done){
  58. done = true;
  59. for (int i = 2; i < a2 + b2 + c2 + 2; i++){
  60. if(array[i] == array[i - 1] && array[i] == array[i -2]){
  61. done = false;
  62. for (int j = 2; j < a2 + b2 + c2 + 2; j++){
  63. if(array[j] != array[i] && array[j] != ' '){
  64. if(i == j - 1){
  65. if(!(array[i] == array[j + 1] && array[i] == array[j + 2])){
  66. aux = array[i];
  67. array[i] = array[j];
  68. array[j] = aux;
  69. break;
  70. }
  71. }
  72. else if(!(array[i] == array[j + 1] && array[i] == array[j + 2]) && !(array[i] == array[j - 1] && array[i] == array[j - 2]) && !(array[i] == array[j - 1] && array[i] == array[j + 1])){
  73. aux = array[i];
  74. array[i] = array[j];
  75. array[j] = aux;
  76. break;
  77. }
  78. else if (j == 2 && (array[i + 1] == array[i])){
  79. aux = array[i];
  80. array[i] = array[j];
  81. array[j] = aux;
  82. break;
  83. }
  84. }
  85. }
  86. }
  87. }
  88. }
  89. string = String.copyValueOf(array);
  90. string = string.substring(2, string.length() - 3);
  91. System.out.println(string);
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement