MWC '15 #5 P3: French Words

View as PDF

Submit solution

Points: 7 (partial)
Time limit: 0.3s
Memory limit: 256M

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

Salarios77 and AndrewNitu are under suspicion of plagiarism, a serious crime at William Lyon Mackenzie CI. They were supposed to complete a project involving writing French words on a piece of paper in alphabetical order and present their definitions to the class. To see if they truly plagiarized, you are to write a program to determine how many words they share in common.

Input Specification

First line consists of N and M separated by a space (0 \le N, M \le 10^6, number of words on Salarios77's and AndrewNitu's respective projects), followed by N spaced strings on the second line, followed by M spaced strings on the third line.

Output Specification

Output the number of words they share in common.

Sample Input

4 4
a b c d
b c z zz

Sample Output



  • 2
    ross_cleary  commented on May 24, 2020, 12:50 p.m.

    To clarify, the question is essentially asking to count the number of distinct words that occur at least once on both lines.

  • 0
    aeternalis1  commented on Aug. 10, 2017, 5:00 p.m. edit 2


    Assuming words in each essay aren't distinct, what would output be in this case:

    5 5

    aa bb bb cc ee

    aa bb ff gg hh

    • 0
      Tearful  commented on Oct. 20, 2017, 6:48 p.m.

      I'm guessing 2? Not sure :v