Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Runde2{
- public static void main(String []args){
- Scanner scan = new Scanner(System.in);
- String zeile = "";
- int zeilenMax = 0;
- int breitenMax = -1;
- List<String> bild = new ArrayList<String>();
- boolean hasError = false;
- if(scan.next().equals("read")) {
- zeilenMax = scan.nextInt();
- for(int i = 1; i <= zeilenMax; i++) {
- if(scan.hasNext()) {
- zeile = scan.next();
- if(breitenMax == -1) breitenMax = zeile.length();
- if(breitenMax == zeile.length()) {
- bild.add(zeile);
- } else {
- hasError = true;
- }
- }
- else{
- hasError = true;
- }
- }
- String eing = "";
- 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!
- {
- eing = scan.next();
- }
- if(!eing.equals("decode")){ hasError = true;}
- if(!hasError) {
- if(eing.equals("decode"))
- {
- if(!Decode(bild,scan.next()))
- {
- System.out.println("INPUT MISMATCH");
- }
- }
- else{
- printlist(bild);
- }
- System.out.println(breitenMax + " " +zeilenMax);
- } else {
- System.out.println("INPUT MISMATCH");
- }
- }
- }
- public static void printlist(List<String> liste)
- {
- for(String item: liste)
- {
- System.out.println(item);
- }
- }
- public static boolean Decode(List<String> element, String key)
- {
- String bigstring= "";
- int zeilenbr = 0;
- String erg="";
- for(String item: element)
- {
- bigstring += item;
- zeilenbr = item.length();
- }
- if(bigstring.length() % key.length()!=0)
- return false;
- int boo = 0;
- while(boo < bigstring.length()/key.length())
- {
- char txt[] = bigstring.substring(boo*key.length(),(boo==0 ? 1:boo+1)*key.length()).toCharArray();
- for(int x=0; x < key.length(); x++)
- {
- int bla = Integer.parseInt(""+key.charAt(x));
- txt[x] = bigstring.substring(boo*key.length(),(boo==0 ? 1:boo+1)*key.length()).toCharArray()[bla];
- }
- erg += new String(txt);
- boo++;
- }
- boo = 0;
- while (boo<erg.length()/zeilenbr)
- {
- System.out.println(erg.substring(boo*zeilenbr,(boo==0 ? 1:boo+1)*zeilenbr));
- boo++;
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement