Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.88 KB | None | 0 0
  1. package ketszemelyes_7_2;
  2. import java.lang.Math;
  3. import java.util.Scanner;
  4.  
  5.  
  6. public class Ketszemelyes_7_2 {
  7.  
  8.     public static void main(String[] args) {
  9.         Scanner sc = new Scanner(System.in);
  10.         System.out.print("Adja meg a kupac elemszámát: ");
  11.         int n = sc.nextInt();
  12.         char[] kupac = new char[n + 1];
  13.         for (int i = 0; i < n + 1; i++)
  14.         {
  15.             kupac[i] = ' ';
  16.         }
  17.  
  18.         kupac[0] = 'V';
  19.         kupac[1] = 'N';
  20.  
  21.         for (int i = 0; i < n + 1; i++) {
  22.             if (kupac[i] == 'V')
  23.             {
  24.                 int j = 0;
  25.                 while ((int)i + Math.pow(2,j) < n + 1)
  26.                 {
  27.                     kupac[i+(int)Math.pow(2,j)] = 'N';
  28.                     j++;
  29.                 }
  30.             }
  31.  
  32.             if (kupac[i] == ' ')
  33.             {
  34.                 int db = 0, nyert = 0;
  35.                 int j = 0;
  36.                 while (i-(int)Math.pow(2, j) > 0)
  37.                 {        
  38.                    
  39.                     db++;
  40.                     if (kupac[i-(int)Math.pow(2, j)] == 'N')
  41.                     {
  42.                         nyert++;
  43.                     }                    
  44.                     j++;
  45.                 }
  46.                 if (nyert == db)
  47.                 {
  48.                     kupac[i] = 'V';
  49.                 }
  50.                 else if (nyert < db)
  51.                     {
  52.                         kupac[i] = 'N';
  53.                     }  
  54.  
  55.             }
  56.        }
  57.  
  58.        for (int i = n; i >= 0; i--) {
  59.             if (i == 0)
  60.                 System.out.println("__________________________________");
  61.             System.out.print("A kupac: " +i +".eleme");
  62.            
  63.             if (kupac[i] == 'N')
  64.                 System.out.println(" - Nyertes állapot");
  65.             else
  66.                 System.out.println(" - Vesztes állapot");
  67.         }
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement