Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Buchstaben;
- import java.util.*;
- public class Zahlen {
- public static void main(String args[]) {
- String str = "abaababaabbabbaabbbbaaaaabbaaabbbbbbaaabbbaaabbbaaaa";
- char[] strArr = str.toCharArray();
- int cnt=0;
- int countEqual=0;
- int countGreater=0;
- ArrayList<Integer> countsAoB = new ArrayList<>();
- ArrayList<Integer> moeglichkeiteins = new ArrayList<>();
- ArrayList<Integer> moeglichkeitzwei = new ArrayList<>();
- ArrayList<Integer> moeglichkeitdrei = new ArrayList<>();
- // a oder b anhand des letzten im String
- char last = strArr[strArr.length-1];
- for (int i = 0; i < strArr.length; ++i)
- {
- if(strArr[i]==last)
- {
- cnt++;
- }
- else
- {
- if(cnt>0)
- {
- countsAoB.add(cnt);
- }
- cnt=0;
- }
- }
- // aufgabe 1
- int letztezahl = countsAoB.get(countsAoB.size() -1);
- for (int i : countsAoB){
- if (i >= letztezahl){
- moeglichkeiteins.add(i);
- }
- }
- // aufgabe 2
- cnt = 0;
- for (int i = 0; i<countsAoB.size(); i++){
- if (countsAoB.get(i) == letztezahl){
- cnt++;
- } else if (cnt > 0){
- moeglichkeitzwei.add(cnt);
- cnt = 0;
- }
- }
- // aufgabe 3
- cnt = 0;
- for (int i = 0; i<countsAoB.size(); i++){
- if (countsAoB.get(i) == letztezahl){
- countEqual++;
- if (countGreater > 0){
- moeglichkeitdrei.add(countGreater);
- countGreater = 0;
- }
- } else if (countsAoB.get(i) > letztezahl) {
- countGreater++;
- if (countEqual > 0){
- moeglichkeitdrei.add(countEqual);
- countEqual = 0;
- }
- } else {
- if (countEqual > 0){
- moeglichkeitdrei.add(countEqual);
- } else if (countGreater > 0){
- moeglichkeitdrei.add(countGreater);
- }
- countEqual = 0;
- countGreater = 0;
- }
- }
- System.out.println(Arrays.toString(countsAoB.toArray()));
- System.out.println(Arrays.toString(moeglichkeiteins.toArray()));
- System.out.println(Arrays.toString(moeglichkeitzwei.toArray()));
- System.out.println(Arrays.toString(moeglichkeitdrei.toArray()));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement