Statement
Consider a string of length N consisting only of lowercase alphabets a-z. Let s[i]
be the character at the i-th position in the string (1-based). The string is a K-string if there are EXACTLY K values of i (1 <= i < N
) such that s[i+1]<s[i]
(we assume 'a'<'b'<'c'<...<'z'
). Given K, find the shortest K-string. If there are multiple solutions, find the lexicographically earliest K-string.
Input
The first line contains the number of test cases T (1<= T <= 100). Each test case contains an integer K (≤ 100). Output
Output
T lines, one for each test case, containing the required string. Use only lower-case letters a-z.
What i cant understand is the case of 27 to 100. I can simply use char array to compute the the problem This isnt the whole algo. I am still trying......
#include<iostream>
using namespace std;
int main()
{
char s[]={'0','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
int k;
cin>>k;
for(int i=k;i>=1;i--)
{
//cout<<s[i+1]<<">"<<s[i];
if(s[i+1]>s[i])
cout<<s[i];
}
system("pause");
return 0;
}