Determine The combination
Input: standard input
Output: standard output
Time Limit: 1 second
Jahir is a student of NSU (
Nice Students' University ). He hates the chapter
Permutation
& Combination of the subject Discrete Math. But his teacher give
him a assignment to generate all the r combination of a string. But he
is too busy with his new girlfriend to do the assignment himself. So he
went to Shabuj, a student of
CSE ( Calculation Science and Engineering ) in BUET (
Bangladesh University of Extraordinary Talents ). He asked him
to make a program to generate the combinations. But Shabuj is always
lazy. He wants your help.
There may be different permutations of the same combination; consider
only the one that has its r
characters in non-decreasing order.
The string consists of only lowercase letters. Any letter can occur
more than once.
Input
The input is
consist of several test cases. Each test case consists of a string s
( the length of s is between 1 and 30 ) and
an integer r ( 0 < r <= length of s
).
Output
For each test case you have to print all different r combinations of s
in lexicographic order in separate line. You can assume there are at
most 1000 different ones.
Problem setter: Hasan Shihab Uddin, CSE, BUET
Thanks to Adrian & Anupam for alternate solution and clarification.
"~~ No matter
wherever you go, bad luck will follow you ~~