Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ketszemelyes_7_2;
- import java.lang.Math;
- import java.util.Scanner;
- public class Ketszemelyes_7_2 {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.print("Adja meg a kupac elemszámát: ");
- int n = sc.nextInt();
- char[] kupac = new char[n + 1];
- for (int i = 0; i < n + 1; i++)
- {
- kupac[i] = ' ';
- }
- kupac[0] = 'V';
- kupac[1] = 'N';
- for (int i = 0; i < n + 1; i++) {
- if (kupac[i] == 'V')
- {
- int j = 0;
- while ((int)i + Math.pow(2,j) < n + 1)
- {
- kupac[i+(int)Math.pow(2,j)] = 'N';
- j++;
- }
- }
- if (kupac[i] == ' ')
- {
- int db = 0, nyert = 0;
- int j = 0;
- while (i-(int)Math.pow(2, j) > 0)
- {
- db++;
- if (kupac[i-(int)Math.pow(2, j)] == 'N')
- {
- nyert++;
- }
- j++;
- }
- if (nyert == db)
- {
- kupac[i] = 'V';
- }
- else if (nyert < db)
- {
- kupac[i] = 'N';
- }
- }
- }
- for (int i = n; i >= 0; i--) {
- if (i == 0)
- System.out.println("__________________________________");
- System.out.print("A kupac: " +i +".eleme");
- if (kupac[i] == 'N')
- System.out.println(" - Nyertes állapot");
- else
- System.out.println(" - Vesztes állapot");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement