DWITE '08 R5 #1 - Baby Diff

View as PDF

Submit solution

Points: 5
Time limit: 2.0s
Memory limit: 64M

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
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 255 characters long.

The output will contain 5 lines of output, integers 0 \le i \le 255 – number of leading characters that are the same between the two lines, up to the first difference.

Note: that 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 0. Make sure not to count the linebreak characters such as \n, \r, or a combination there of.

Sample Input

tony
tony
dan
tony
one two three
one two four
a
b
abcd
abcde

Sample Output

4
0
8
0
4

Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0) Problem Resource: DWITE


Comments

There are no comments at the moment.