Guest User

Untitled

a guest
May 20th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.38 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class LastKing{
  4.  
  5.     public static void main (String [] args){
  6.        
  7.         Scanner sc = new Scanner(System.in);
  8.        
  9.         final int K = 6;
  10.         final int P = 4;
  11.         int [][] c = new int [K][P];
  12.        
  13.         final int x = 48;
  14.        
  15.         int stIp=99;
  16.         int stPl=99;
  17.        
  18.         for(int i=1; i<=K; i++){
  19.             vpisi(i, 0, c, K);
  20.         }
  21.        
  22.         izpis(c, P, K);
  23.        
  24.         while(stIp!=-1){
  25.             boolean run = true;
  26.             while(run){
  27.                
  28.                 System.out.print("\nVnesite ukaz: ");
  29.                 String lol = sc.next();
  30.                 char a = lol.charAt(0);
  31.                 stIp = (int) (a - x)-1;
  32.                 if(stIp<0 || stIp>P-1){
  33.                     //System.out.println(stIp);
  34.                     if(stIp==-1){
  35.                         run = false;
  36.                     }else{
  37.                         System.out.println("\nNapacen vnos!");
  38.                     }
  39.                     }else{
  40.                     char b = lol.charAt(1);
  41.                     stPl = (int) (b - x)-1;
  42.                     if(stPl<0 || stPl>P-1){
  43.                         System.out.println("\nNapacen vnos!");
  44.                     }else{
  45.                         //System.out.println(stIp+" "+stPl);
  46.                         if(c[K-1][stIp]==0){
  47.                             System.out.println("\nPladenj s stevilko "+(stIp+1)+" je prazen.");
  48.                         }else{
  49.                             if((stIp+1)==0){
  50.                                 run=false;
  51.                             }else{
  52.                                 if(stIp+1>=1 && stIp+1<=P && stPl+1>=1 && stPl+1<=P){
  53.                                     run = false;
  54.                                     //System.out.println("oki"+stIp+" "+stPl);
  55.                                 }
  56.                             }
  57.                         }
  58.                     }
  59.                 }
  60.             }
  61.             if(!run && (stIp+1)!=0 && (stPl+1)!=0){
  62.                 int stt = number(stIp, c, K);
  63.                 //System.out.println("oki"+stIp+" "+stPl+" "+stt);
  64.                 vpisi(stt, stPl, c, K);
  65.                 //System.out.println("oki"+stIp+" "+stPl);
  66.                 izpis(c, P, K);
  67.             }
  68.             System.out.println("\n");
  69.         }
  70.         System.out.print("Konec!\n");
  71.     }
  72.     public static int number(int stIp,int[][] c,int K){
  73.         for(int i=0; i<K; i++){
  74.             if(c[i][stIp]!=0){
  75.                 int l = c[i][stIp];
  76.                 c[i][stIp]=0;
  77.                 return l;
  78.             }
  79.         }
  80.         return 0;
  81.     }
  82.     public static void vpisi(int stt, int stPl,int[][] c,int K){
  83.         for(int i=(K-1); i>=0; i--){
  84.             if(c[i][stPl]==0){
  85.                 c[i][stPl]=stt;
  86.                 break;
  87.             }
  88.         }
  89.     }
  90.     public static void izpis(int [][]c, int P, int K){
  91.         System.out.println();
  92.         for(int i=0; i<K; i++){
  93.             for(int n=0; n<P; n++){
  94.                 if(c[i][n]==0){
  95.                     System.out.print("    ");
  96.                 }else{
  97.                     System.out.print(" "+c[i][n]+"  ");
  98.                 }
  99.             }
  100.             System.out.println();
  101.         }
  102.         for(int i=0; i<P; i++){
  103.             System.out.print("--- ");
  104.         }
  105.         System.out.println();
  106.         for(int i=1; i<=P; i++){
  107.             System.out.print(" "+i+"  ");
  108.         }
  109.         System.out.println();
  110.     }
  111.    
  112. }
Add Comment
Please, Sign In to add comment