## Mock CCC '20 S1 - War

View as PDF

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

Author:
Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

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

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

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

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

I am having trouble, I can't deny it

• 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.

• commented on Aug. 14, 2020, 4:35 p.m.

Thanks a lot. I mean it.