Solution to First Common Nodes In Lists from Jobdu

7 Sep

No test case content is given. No response from the admin. No clear statement is provided. I spent a whole day on the input issue. And I still do not know what is wrong with my original input handler. Save your life, and stay away from this OJ.

Question (in Chinese): http://ac.jobdu.com/problem.php?pid=1505

Question Name: First Common Nodes In Lists

Question Description: Given two integer arrays, find the first node with the same value.

Input: the input might contain multiple test cases. Each test case contains three lines. The first line includes two integers N and M (1 <= N, M <= 1000), saying the number of elements in the two arrays. The second line includes N integers as the content of the first array. And the third line includes M integers as the content of the second array.

Output: for each test case, find the first node with the same value and print out the value, if exist. Otherwise, print “My God”.

The solution is: