Mock CCC '20 S1 - War

View as PDF

Submit solution

Points: 3 (partial)
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type

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 opponent's hands, can you tell Larry how many battles will occur?

Input Specification

The first line will contain an integer N (1 \le N \le 1000), the number of cards in each hand.

The next line will contain N integers a_i (1 \le a_i \le 11), the values of the cards in Larry's hand from start to end.

The final line will contain N integers b_i (1 \le b_i \le 11), 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


  • 1
    glasa  commented on June 22, 2020, 6:54 p.m.

    Anyone else having trouble with this question or am I just dumb?


    • 3
      AlanL  commented on June 23, 2020, 3:47 p.m.

      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.


      • 0
        ItzMidnightShadowWolf  commented on Aug. 14, 2020, 8:35 p.m.

        Thanks a lot. I mean it.


        • 9
          Ben_Dover  commented on Jan. 31, 2021, 12:04 a.m.

          Yes thanks a lot. I declare war on Nigeria.