Advertisement
Guest User

Untitled

a guest
Feb 17th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. package Buchstabenkette;
  2. import java.util.*;
  3.  
  4. public class Zahlen {
  5. public static void main(String args[]) {
  6. String str = "abaababaabbabbaabbbbaaaaabbaaabbbbbba";
  7. char[] strArr = str.toCharArray();
  8. int cnt=0;
  9. int countEqual=0;
  10. int countGreater=0;
  11.  
  12. ArrayList<Integer> countsAoB = new ArrayList<>();
  13.  
  14. ArrayList<Integer> moeglichkeiteins = new ArrayList<>();
  15. ArrayList<Integer> moeglichkeitzwei = new ArrayList<>();
  16. ArrayList<Integer> moeglichkeitdrei = new ArrayList<>();
  17.  
  18.  
  19. // a oder b anhand des letzten im String
  20. char last = strArr[strArr.length-1];
  21.  
  22. for (int i = 0; i < strArr.length; ++i)
  23. {
  24. if(strArr[i]==last)
  25. {
  26. cnt++;
  27. }
  28. else
  29. {
  30. if(cnt>0)
  31. {
  32. countsAoB.add(cnt);
  33. }
  34.  
  35. cnt=0;
  36. }
  37. }
  38.  
  39. // aufgabe 1
  40.  
  41. int letztezahl = countsAoB.get(countsAoB.size() -1);
  42.  
  43. for (int i : countsAoB){
  44. if (i >= letztezahl){
  45. moeglichkeiteins.add(i);
  46. }
  47. }
  48.  
  49. // aufgabe 2
  50. cnt = 0;
  51. for (int i = 0; i<countsAoB.size(); i++){
  52.  
  53. if (countsAoB.get(i) >= letztezahl){
  54. cnt++;
  55. } else {
  56. moeglichkeitzwei.add(cnt);
  57. cnt = 0;
  58. }
  59. }
  60. // aufgabe 3
  61.  
  62. cnt = 0;
  63. for (int i = 0; i<countsAoB.size(); i++){
  64.  
  65. }
  66. // __
  67. for (int i = 0; i<countsAoB.size(); i++){
  68. if (countsAoB.get(i) == letztezahl){
  69.  
  70. countEqual++;
  71. if (countGreater > 0){
  72. countGreater = 0;
  73. moeglichkeitdrei.add(countGreater);
  74. }
  75. } else if (countsAoB.get(i) > letztezahl) {
  76. countGreater++;
  77. if (countEqual > 0){
  78. countEqual = 0;
  79. moeglichkeitdrei.add(countEqual);
  80. }
  81. } else {
  82. if (countEqual > 0){
  83. moeglichkeitdrei.add(countEqual);
  84. } else if (countGreater > 0){
  85. moeglichkeitdrei.add(countGreater);
  86. }
  87. countEqual = 0;
  88. countGreater = 0;
  89. }
  90.  
  91. System.out.println(Arrays.toString(countsAoB.toArray()));
  92. System.out.println(Arrays.toString(moeglichkeiteins.toArray()));
  93. System.out.println(Arrays.toString(moeglichkeitzwei.toArray()));
  94. System.out.println(Arrays.toString(moeglichkeitdrei.toArray()));
  95. }
  96.  
  97.  
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement