Skip to content

Instantly share code, notes, and snippets.

@Gi-Totev
Created August 30, 2020 15:36
Show Gist options
  • Save Gi-Totev/22c17ccf3efe561f1b1f977dcb3f9937 to your computer and use it in GitHub Desktop.
Save Gi-Totev/22c17ccf3efe561f1b1f977dcb3f9937 to your computer and use it in GitHub Desktop.
Stack/Q
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
ArrayDeque<Integer> stackLily = new ArrayDeque<>();
ArrayDeque<Integer> queueRose = new ArrayDeque<>();
int wreath = 0;
int storage = 0;
int[] lily = Arrays.stream(scanner.nextLine().split(", ")).mapToInt(Integer::parseInt).toArray();
int[] rose = Arrays.stream(scanner.nextLine().split(", ")).mapToInt(Integer::parseInt).toArray();
for (int i : lily) {
stackLily.push(i);
}
for (int i : rose) {
queueRose.offer(i);
}
while(!stackLily.isEmpty() && !queueRose.isEmpty() && wreath < 5)
{
int flowerSum = stackLily.peekFirst() + queueRose.peekFirst();
if(flowerSum == 15)
{
wreath++;
stackLily.pop();
queueRose.poll();
} else if (flowerSum > 15)
{
int reduce = stackLily.peekFirst() - 2;
stackLily.pop();
stackLily.push(reduce);
} else {
storage += stackLily.pop() + queueRose.poll();
}
}
wreath += storage / 15;
if(wreath >= 5) {
System.out.println("You made it, you are going to the competition with " + wreath + " wreaths!" );
} else
{
int left = 5 - wreath;
System.out.println("You didn't make it, you need " + left + " wreaths more!");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment