Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class Card {
- private int type;
- private int health;
- private int magicPower;
- public Card(int type, int health, int magicPower) {
- this.type = type;
- this.health = health;
- this.magicPower = magicPower;
- }
- public int getType() {
- return type;
- }
- public void setType(int type) {
- this.type = type;
- }
- public int getHealth() {
- return health;
- }
- public void setHealth(int health) {
- this.health = health;
- }
- public int getMagicPower() {
- return magicPower;
- }
- public void setMagicPower(int magicPower) {
- this.magicPower = magicPower;
- }
- public int significance() {
- return health * magicPower;
- }
- @Override
- public String toString() {
- return String.valueOf(type);
- }
- }
- class SLLNode<E> {
- protected E element;
- protected SLLNode<E> succ;
- public SLLNode(E elem, SLLNode<E> succ) {
- this.element = elem;
- this.succ = succ;
- }
- @Override
- public String toString() {
- return element.toString();
- }
- }
- class SLL<E> {
- private SLLNode<E> first;
- public SLL() {
- this.first = null;
- }
- public void deleteList() {
- first = null;
- }
- public int size() {
- int ret;
- if (first != null) {
- SLLNode<E> tmp = first;
- ret = 1;
- while (tmp.succ != null) {
- tmp = tmp.succ;
- ret++;
- }
- return ret;
- } else
- return 0;
- }
- @Override
- public String toString() {
- String ret = new String();
- if (first != null) {
- SLLNode<E> tmp = first;
- ret += tmp;
- while (tmp.succ != null) {
- tmp = tmp.succ;
- ret += " " + tmp;
- }
- } else
- ret = "Prazna lista!!!";
- return ret;
- }
- public void insertFirst(E o) {
- SLLNode<E> ins = new SLLNode<E>(o, first);
- first = ins;
- }
- public void insertAfter(E o, SLLNode<E> node) {
- if (node != null) {
- SLLNode<E> ins = new SLLNode<E>(o, node.succ);
- node.succ = ins;
- } else {
- System.out.println("Dadenot jazol e null");
- }
- }
- public void insertBefore(E o, SLLNode<E> before) {
- if (first != null) {
- SLLNode<E> tmp = first;
- if (first == before) {
- this.insertFirst(o);
- return;
- }
- while (tmp.succ != before)
- tmp = tmp.succ;
- if (tmp.succ == before) {
- SLLNode<E> ins = new SLLNode<E>(o, before);
- tmp.succ = ins;
- } else {
- System.out.println("Elementot ne postoi vo listata");
- }
- } else {
- System.out.println("Listata e prazna");
- }
- }
- public void insertLast(E o) {
- if (first != null) {
- SLLNode<E> tmp = first;
- while (tmp.succ != null)
- tmp = tmp.succ;
- SLLNode<E> ins = new SLLNode<E>(o, null);
- tmp.succ = ins;
- } else {
- insertFirst(o);
- }
- }
- public E deleteFirst() {
- if (first != null) {
- SLLNode<E> tmp = first;
- first = first.succ;
- return tmp.element;
- } else {
- System.out.println("Listata e prazna");
- return null;
- }
- }
- public E delete(SLLNode<E> node) {
- if (first != null) {
- SLLNode<E> tmp = first;
- if (first == node) {
- return this.deleteFirst();
- }
- while (tmp.succ != node && tmp.succ.succ != null)
- tmp = tmp.succ;
- if (tmp.succ == node) {
- tmp.succ = tmp.succ.succ;
- return node.element;
- } else {
- System.out.println("Elementot ne postoi vo listata");
- return null;
- }
- } else {
- System.out.println("Listata e prazna");
- return null;
- }
- }
- public SLLNode<E> getFirst() {
- return first;
- }
- public SLLNode<E> find(E o) {
- if (first != null) {
- SLLNode<E> tmp = first;
- while (tmp.element != o && tmp.succ != null)
- tmp = tmp.succ;
- if (tmp.element == o) {
- return tmp;
- } else {
- System.out.println("Elementot ne postoi vo listata");
- }
- } else {
- System.out.println("Listata e prazna");
- }
- return first;
- }
- }
- public class MysticalCardGame {
- //TODO: implement function
- public static void startDuel(SLL<Card> firstSorcererCards, SLL<Card> secondSorcererCards) {
- SLLNode<Card> move = firstSorcererCards.getFirst();
- SLLNode<Card> max = firstSorcererCards.getFirst();
- while (move != null) {
- if (move.element.significance() > max.element.significance()) {
- max = move;
- }
- move = move.succ;
- }
- SLLNode<Card> move2 = secondSorcererCards.getFirst();
- for (int i = 0; i < secondSorcererCards.size()/2; i++) {
- move2 = move2.succ;
- }
- secondSorcererCards.insertBefore(max.element, move2);
- firstSorcererCards.delete(max);
- }
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- SLL<Card> firstSorcererCards = new SLL<Card>();
- SLL<Card> secondSorcererCards = new SLL<Card>();
- for (int i = 0; i < 6; i++) {
- String line = scanner.nextLine();
- String[] parts = line.split("\\s+");
- firstSorcererCards.insertLast(new Card(Integer.parseInt(parts[0]), Integer.parseInt(parts[1]), Integer.parseInt(parts[2])));
- }
- for (int i = 0; i < 6; i++) {
- String line = scanner.nextLine();
- String[] parts = line.split("\\s+");
- secondSorcererCards.insertLast(new Card(Integer.parseInt(parts[0]), Integer.parseInt(parts[1]), Integer.parseInt(parts[2])));
- }
- startDuel(firstSorcererCards, secondSorcererCards);
- System.out.println(firstSorcererCards);
- System.out.println(secondSorcererCards);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement