As a child, Larry always played War with his friends. If you are not aware, War is a card game with simple rules. This version may be different from a version you have played.
Each player flips over the first card in their hand.
Whichever player has the higher card takes all the cards on the table into their winnings (not their hand).
However, if both revealed cards are the same… they remain on the table.
Repeat until either player has no cards left in their hand.
If there are cards left on the table, they are left.
The person with the most cards in their winnings wins, or it is a tie if they are equal.
However, Larry is a fan of violence, and doesn't particularly care who wins. Because of this, he wants to know how much war will occur in his game. Whenever the two players' cards are the same, a battle begins, which ends when the cards are won by someone.
Given some sequence of cards for Larry and his opponents decks, can you tell Larry how many battles will occur?
Input Specification
The first line contains an integer , the amount of cards in each hand.
The next line will contain integers
, the values of the cards in Larry's hand from start to end.
The final line will contain integers
, the values of the cards in Larry's opponent's hand from start to end.
Output Specification
You are to print one line, the number of battles that occurred.
Sample Input
5
1 1 2 4 3
1 2 2 4 1
Sample Output
2
Comments
I'm not sure if I am misunderstanding the question or being an idiot with the way I approach it, I'm getting WA for the 4th case and I'm not sure why.
Anyone else having trouble with this question or am I just dumb?
I am having trouble, I can't deny it
Read the question carefully, especially the definition of "war" and what the problem wants you to solve for. Right now your solution/approach is not what the problem is asking.
Thanks a lot. I mean it.