Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.75 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class AsciiShop3 {
  4.  
  5.     /**
  6.      * @param args
  7.      */
  8.     public static void main(String[] args) {
  9.         // TODO Auto-generated method stub
  10.         Scanner input = new Scanner(System.in);
  11.         AsciiImage a = new AsciiImage();
  12.         boolean check = true;
  13.         int i=-1;
  14.         int lines=0;
  15.         if(input.next().equals("read")){
  16.             lines=input.nextInt();
  17.         }else{
  18.             check = false;
  19.         }
  20.         while(input.hasNext() && check==true){
  21.             if(i==-1){
  22.                 String bugfix = input.nextLine();  //irgendwie wird durch die kombination aus der read abfrage und der while bedingung ein leerer input erzeugt welcher hiermit abgefangen wird
  23.                 i++;
  24.             }else{
  25.                 check=a.addLine(input.nextLine());
  26.                 i++;
  27.                 if(i==lines || check==false){
  28.                     break;
  29.                 }
  30.             }
  31.         }
  32.         if(check==false){
  33.             System.out.print("INPUT MISMATCH");
  34.         }else{
  35.         /*  System.out.println("OUPUT\n"+a.toString());
  36.             a.toString(); */
  37.             System.out.println("Tostring\n"+a.toString());
  38.             a.transpose();         
  39.             System.out.println("Transpose\n"+a.toString());
  40.         /*  a.flipV();
  41.             System.out.println("Flip\n"+a.toString());
  42.             System.out.println(a); */
  43.         }
  44.     }
  45.  
  46. }
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53. second file
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60. public class AsciiImage {
  61.     private String s;
  62.     private int w; //width
  63.     private int h; //height
  64.     private String output;
  65.    
  66.    
  67.     public AsciiImage(){
  68.         s ="";
  69.         w=0;
  70.         h=0;
  71.    
  72.     }
  73.      
  74.     public boolean addLine(String line){
  75.         boolean b=false;
  76.         if(line.length()!=0){  //bug: kein abbruch trotz leerer eingabe
  77.             if(h==0){
  78.                 w=line.length();
  79.             //  System.out.println("passt");
  80.             }  
  81.             b=true;
  82.            // System.out.println("passt2");
  83.             if(line.length() == w ){
  84.                 //  s+=line+"\n";
  85.                 s+=line;
  86.                 h++;
  87.                 //System.out.println("w= "+w);
  88.             }else{
  89.                 b = false;
  90.             }
  91.         }else{
  92.             System.out.println("fehler2");
  93.         }
  94.         //System.out.println(w+"w<-->h"+h);
  95.         return b;
  96.     }
  97.  
  98.     public int getWidth(){
  99.         return w;
  100.     }
  101.  
  102.     public int getHeight(){
  103.         return h;
  104.     }
  105.  
  106.     public String toString(){
  107.         output=s;
  108.         //output=new StringBuffer(s).deleteCharAt(w*h).toString();
  109.         //System.out.println("tostringfunktion - s: "+s+ "w = "+w);
  110.         for(int i=1;i<=h;i++){
  111.                 output= new StringBuffer(output).insert(w*i+i-1, "\n").toString();
  112.         }
  113.         return output;
  114.     }
  115.  
  116.  /*   public int getUniqueChars(){
  117.        
  118.     }
  119.     //  gibt zurück wieviele unterschiedliche Zeichen im Bild vorkommen. So enthält das einzeilige Bild abaaabac 3 unterschiedliche Zeichen. */
  120.  
  121.     public void flipV(){
  122.         int j=0;
  123.         String temp="";
  124.         for(int i=h*w;i>0;i--){
  125.             j++;
  126.             temp=new StringBuffer(s).insert(j, s.charAt(i)).toString();
  127.         }
  128.         s=temp;
  129.     }
  130.     //  dreht das Bild vertikal um, sprich es vertauscht die Zeilen des Bildes (die erste mit der letzten, die zweite mit der vorletzten, usw.)
  131.  
  132.     public void transpose(){
  133.         String temp=s;
  134.         int tmp=0;
  135.         for(int i=0;i<w*h;i++){
  136.             //for(int j=1;j<w*h;j++){
  137.         //      if(w*i+i!=w*h){
  138.                 temp=new StringBuffer(s).insert(i, s.charAt((w*i+i)%(w*h))).toString();
  139.          /*     }else{
  140.                 temp=new StringBuffer(s).insert(i, s.charAt((w*i+i)%(w*h))).toString();
  141.             } */
  142.                
  143.                 //BUG: i+w*i%w*h irgendwas passt nicht
  144.         //  }
  145.         }
  146.         tmp=h;
  147.         h=w;
  148.         w=tmp;
  149.         System.out.println(w+" "+h);
  150.         //s=temp;
  151.     }
  152.     //  vertauscht Zeilen und Spalten des Bildes, sprich aus der ersten Zeile im Bild wird die erste Spalte usw. Dabei ändern sich Höhe und Breite des Bildes (vgl. Matrix_(Mathematik)). Diese Methode muss sicherstellen, dass abhängige Eigenschaften des Bildes (Höhe, Breite) aktualisiert werden.
  153.  
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement