DWITE Online Computer Programming Contest, February 2009, Problem 1
While diff is a useful text processing utility that finds the differences between contents of files, this baby diff will start out as a simplistic check, counting how many of the leading characters of two lines of text are the same. The hopes and dreams of this program is to grow up into a full-fledged utility, but for now, it starts small.
The input will contain 5 sets of input, two lines each. Each line will be a non-empty string, less than characters long.
The output will contain 5 lines of output, integers – number of leading characters that are the same between the two lines, up to the first difference.
Note: the two lines could be of different length. The counter stops before the first character that doesn't match, so two strings that start differently would have a result of . Make sure not to count the linebreak characters such as \n
, \r
, or a combination thereof.
Sample Input
tony
tony
dan
tony
one two three
one two four
a
b
abcd
abcde
Sample Output
4
0
8
0
4
Problem Resource: DWITE
Comments