Mock CCC '20 S1 - War

View as PDF

Submit solution

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

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 opponents decks, can you tell Larry how many battles will occur?

Input Specification

The first line contains an integer N\ (1 \leq N \leq 1000), the amount of cards in each hand.

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

The final line will contain N integers b_i\ (1 \leq b_i \leq 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

1 1 2 4 3
1 2 2 4 1

Sample Output



  • 0
    qiao_yun20060930  commented on May 4, 2021, 10:01 p.m.

    anyone could help me on my python3 solution?

  • 1
    AesthicEthics  commented on Dec. 28, 2020, 4:48 p.m. edit 2

    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.

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

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

    • 1
      ItzMidnightShadowWolf  commented on Aug. 14, 2020, 4:34 p.m.

      I am having trouble, I can't deny it

    • 3
      AlanL  commented on June 23, 2020, 11:47 a.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, 4:35 p.m.

        Thanks a lot. I mean it.

        • 5
          Ben_Dover  commented on Jan. 30, 2021, 7:04 p.m.

          Yes thanks a lot. I declare war on Nigeria.