I have three strings as the input (A,B,C).
A = "SLOVO", B = "WORD", C =

And I need to find algorithm which decide, if the string C is a concatenation of infinite repetiton strings A and B. Example of repetition: A^2 = "SLOVOSLOVO" and in the string C is first 8 letters "SLOVOSLO" from "SLOVOSLOVO". String B is similar.
My idea for algorithm:
index_A = 0; //index of actual letter of string A
index_B = 0;
Go throught the hole string C from 0 to size(C)
{
Pick the actual letter from C (C[i])
if(C[i] == A[index_A] && C[i] != B[index_B])
{
index_A++;
Go to next letter in C
}
else if(C[i] == B[index_B] && C[i] != A[index_A])
{
index_B++;
Go to next letter in C
}
else if(C[i] == B[index_B] && C[i] == A[index_A])
{
Now we couldn´t decice which way to go, so we should test both options (maybe recusrsion)
}
else
{
return false;
}
}
It´s only quick description of the algorithm but I hope you understand main idea of this algorithm should do. Is this the way of solving this problem good? Do you have better solution? Or some tips?