fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. static void codieren(String s){
  11. int Zähler = 0;
  12. char[] a = s.toUpperCase().toCharArray();
  13. for (int i = 0; i<s.length()-2; i++){
  14. if (a[i] == a[i+1] && a[i] ==a[i+2]){
  15. Zähler = 3;
  16. while ((i+Zähler) < s.length() && a[i] == a[i+Zähler]) {
  17. Zähler++;
  18. }
  19. i = i + Zähler - 1;
  20. }
  21. System.out.print(a[i]);
  22. if (Zähler != 0) {
  23. System.out.print(String.valueOf(Zähler));
  24. }
  25. }
  26. }
  27.  
  28. public static void main (String[] args) throws java.lang.Exception
  29. {
  30. //Out.println("Geben sie eine Reihenfolge von Buchstaben ein!");
  31. //Instead of reading, I'm just going to hard-code it. You don't need to do that.
  32. //String s = In.readString();
  33. String s = "abbcccdddd";
  34. //Out.println("Die Codierung lautet:");
  35. try {
  36. codieren(s);
  37. } catch (Exception e) {
  38. e.printStackTrace(System.out);
  39. }
  40. }
  41. }
Success #stdin #stdout 0.07s 380160KB
stdin
Standard input is empty
stdout
ABBC3D4