Hi! I found the wrong in this program. Is very simple!!
You write:
for(int s=0;s<k-1;s++) {

the correct is:
for(int s=0;s<=k-1;s++) {

ok???
thank you and...