CS4HS Summer Program for HS Teachers

Root of a string

July 2011
Problem 1

The root of string S is the shortest string T such that S=TTTTT...T. That is, you can obtain S by concatenating T with itself many times.

The input file DATA1.txt will contain 5 lines, with each line having one non-empty string over the alphabet {a, b, c, ..., z}.

The output file OUT1.txt will contain 5 lines. Each line contains the root of the corresponding line in DATA1.txt.

Sample Input (only first 3 shown):
bbbbbbbbbbbb
abcddeffab
ataaattaataaattaataaattaataaatta
Sample Output (only first 3 shown):
b
abcddeffab
ataaatta