简体   繁体   中英

Construction of a string

You are given three positive integers n, a and b. You have to construct a string s of length n consisting of lowercase Latin letters such that each substring of length a has exactly b distinct letters.

Please provide hints on how to solve. Please dont solve the question. Should I use arrays?

No. This is an easy problem, not necessary to use any external memory like-array or others.

You need just to iterate the loop and generate the characters so that you can construct a string following given conditions. As you are generating characters, you can use ASCII values per iteration with loop to print the characters sequentially (not randomly, otherwise you may confuse).


Again no need to think about the occurrence of exact b numbers of characters in each substrings as you are only generating the b number of characters each time.

Hopeful to your understanding


example : (in C++)

for(int i = 0;  i < n; ++i)
 cout<<char('a'+i%b);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM