Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MyClass {
- public static void main(String args[]) {
- java.util.Scanner scanner = new java.util.Scanner(System.in);
- String[] houses = scanner.nextLine().split("@");
- int[] house = new int[houses.length];
- for(int i = 0;i < houses.length;i++) {
- house[i] = Integer.parseInt(houses[i]);
- }
- int modCap = houses.length -1;
- int lastPosition = 0;
- String nextLine = null;
- int houseIndex = 0;
- while(true) {
- nextLine = scanner.nextLine();
- if (nextLine.equals("Love!")) {
- break;
- } else {
- String[] jumpIndex = nextLine.split(" ");
- int jumpIdx = Integer.parseInt(jumpIndex[1]);
- // houseIndex = (houseIndex + jumpIdx) % modCap;
- houseIndex += jumpIdx;
- if (houseIndex > modCap) {
- houseIndex = 0;
- }
- if (house[houseIndex] != 0) {
- house[houseIndex] -= 2;
- if (house[houseIndex] == 0) {
- System.out.printf("Place %d has Valentine's day.\n",houseIndex);
- }
- } else {
- System.out.printf("Place %d already had Valentine's day.\n",houseIndex);
- }
- lastPosition = houseIndex;
- }
- }
- System.out.printf("Cupid's last position was %d.\n",lastPosition);
- if (failsCount(house) == 0) {
- System.out.println("Mission was successful.");
- } else {
- System.out.printf("Cupid has failed %d places.",failsCount(house));
- }
- }
- public static int failsCount(int[] houses) {
- int fails = 0;
- for(int i = 0; i < houses.length;i++) {
- if (houses[i] > 0) {
- fails++;
- }
- }
- return fails;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement