dimanche 11 août 2019

Spiral Pattern string [on hold]

matrix, m rows and n columns, and a string s print the matrix such that the spiral in the matrix is formed using the characters in the string. Note that the string is circular. Direction of the spiral is clockwise inward.

input 
4 8 6
abcdef

output 
abcdefab
bcdefabc
abafedcd
fedcbafe

int index = 0;
for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
        cout<<s[index];
        index = (index + 1) % k;
    }
    cout<<"\n";
}

but im getting output 
abcdefab
cdefabcd
efabcdef
abcdefab

it will print in spiral pattern

Aucun commentaire:

Enregistrer un commentaire