Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2020
403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class KaminoFactory_09 {
  4.  
  5. public static void main(String[] args) {
  6. Scanner scan = new Scanner(System.in);
  7. int lengthOfSequences = Integer.parseInt(scan.nextLine());
  8. String input = scan.nextLine();
  9. int coutPreviousElement = 0, generalCounter = 0, indexPrevious = 0, curentSum = 0, previousSum = 0,
  10. bestSequenceIndex = 0, bestSequenceSum = 0;
  11. int[] outputArray = new int[lengthOfSequences];
  12. while (!input.equals("Clone them!")) {
  13. generalCounter++;
  14. String[] array = input.split("!+");
  15. int[] integerArray = new int[array.length];
  16.  
  17. for (int i = 0; i < integerArray.length; i++) {
  18. integerArray[i] = Integer.parseInt(array[i]);
  19. }
  20. int curentCounter = 1, counter = 0, index = 0;
  21. if (integerArray.length == 1) {
  22. counter = 1;
  23. }
  24. for (int i = 0; i < integerArray.length - 1; i++) {
  25. if (integerArray[i] == 1) {
  26. curentSum += 1;
  27. }
  28. if (integerArray[i] == integerArray[i + 1] && integerArray[i] == 1) {
  29. curentCounter++;
  30. if (counter < curentCounter) {
  31. counter = curentCounter;
  32. index = i;
  33. }
  34. } else {
  35. if (counter < curentCounter) {
  36. counter = curentCounter;
  37. }
  38. curentCounter = 1;
  39. }
  40. }
  41. if (coutPreviousElement == counter) {
  42. if (indexPrevious == index && curentSum > previousSum) {
  43. for (int i = 0; i < integerArray.length; i++) {
  44. outputArray[i] = integerArray[i];
  45. }
  46. bestSequenceIndex = generalCounter;
  47. } else if (indexPrevious > index) {
  48. for (int i = 0; i < integerArray.length; i++) {
  49. outputArray[i] = integerArray[i];
  50. }
  51. bestSequenceIndex = generalCounter;
  52. }
  53. } else if (coutPreviousElement < counter) {
  54. for (int i = 0; i < integerArray.length; i++) {
  55. outputArray[i] = integerArray[i];
  56. }
  57. bestSequenceIndex = generalCounter;
  58. coutPreviousElement = counter;
  59. previousSum = curentSum;
  60. }
  61. indexPrevious = index;
  62. curentSum = 0;
  63. input = scan.nextLine();
  64. }
  65. for (int i = 0; i < outputArray.length; i++) {
  66. if (outputArray[i] == 1) {
  67. bestSequenceSum++;
  68. }
  69. }
  70. System.out.printf("Best DNA sample %d with sum: %d.%n", bestSequenceIndex, bestSequenceSum);
  71. for (int i : outputArray) {
  72. System.out.print(i + " ");
  73. }
  74.  
  75. }
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement