Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Runde2{
  4. public static void main(String []args){
  5. Scanner scan = new Scanner(System.in);
  6. String zeile = "";
  7. int zeilenMax = 0;
  8. int breitenMax = -1;
  9. List<String> bild = new ArrayList<String>();
  10. boolean hasError = false;
  11. if(scan.next().equals("read")) {
  12. zeilenMax = scan.nextInt();
  13. for(int i = 1; i <= zeilenMax; i++) {
  14. if(scan.hasNext()) {
  15. zeile = scan.next();
  16.  
  17. if(breitenMax == -1) breitenMax = zeile.length();
  18. if(breitenMax == zeile.length()) {
  19. bild.add(zeile);
  20.  
  21. } else {
  22. hasError = true;
  23. }
  24.  
  25. }
  26. else{
  27. hasError = true;
  28. }
  29. }
  30. String eing = "";
  31. if(scan.hasNext())//hier musst du halt schauen ob noch eine zeile da ist, hatte keine zeit nachzuschaune wie man das prüft, hier gehts einfach nur um deine überprüfung der zeilen!
  32. {
  33. eing = scan.next();
  34. }
  35. if(!eing.equals("decode")){ hasError = true;}
  36. if(!hasError) {
  37. if(eing.equals("decode"))
  38. {
  39. if(!Decode(bild,scan.next()))
  40. {
  41. System.out.println("INPUT MISMATCH");
  42. }
  43. }
  44. else{
  45. printlist(bild);
  46. }
  47. System.out.println(breitenMax + " " +zeilenMax);
  48. } else {
  49. System.out.println("INPUT MISMATCH");
  50. }
  51.  
  52. }
  53. }
  54. public static void printlist(List<String> liste)
  55. {
  56. for(String item: liste)
  57. {
  58. System.out.println(item);
  59. }
  60. }
  61. public static boolean Decode(List<String> element, String key)
  62. {
  63. String bigstring= "";
  64. int zeilenbr = 0;
  65. String erg="";
  66. for(String item: element)
  67. {
  68. bigstring += item;
  69. zeilenbr = item.length();
  70. }
  71. if(bigstring.length() % key.length()!=0)
  72. return false;
  73. int boo = 0;
  74.  
  75. while(boo < bigstring.length()/key.length())
  76. {
  77. char txt[] = bigstring.substring(boo*key.length(),(boo==0 ? 1:boo+1)*key.length()).toCharArray();
  78. for(int x=0; x < key.length(); x++)
  79. {
  80. int bla = Integer.parseInt(""+key.charAt(x));
  81. txt[x] = bigstring.substring(boo*key.length(),(boo==0 ? 1:boo+1)*key.length()).toCharArray()[bla];
  82. }
  83. erg += new String(txt);
  84. boo++;
  85. }
  86. boo = 0;
  87. while (boo<erg.length()/zeilenbr)
  88. {
  89. System.out.println(erg.substring(boo*zeilenbr,(boo==0 ? 1:boo+1)*zeilenbr));
  90. boo++;
  91. }
  92. return true;
  93.  
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement