#C99. Lexicographically Smallest and Largest Substrings
Lexicographically Smallest and Largest Substrings
Lexicographically Smallest and Largest Substrings
Given a string \(S\) of length \(N\) and an integer \(K\), your task is to find the lexicographically smallest and largest substrings of \(S\) of length \(K\). A substring is a contiguous sequence of characters within a string.
Note: The lexicographical order is defined as the natural order of characters. For example, "a" is lexicographically smaller than "b" and "abc" is lexicographically smaller than "abd".
Input/Output Format: The input is taken from standard input (stdin) and the output is printed to standard output (stdout). Your program should read the string \(S\), the integer \(N\) (which is the length of \(S\)), and the integer \(K\) in that order.
The output should consist of two lines: the first line contains the smallest substring of length \(K\) and the second line contains the largest substring of length \(K\).
Constraints:
- \(1 \leq K \leq N \leq 10^3\)
- \(S\) consists of lowercase English letters.
Examples:
Input: welcometojava 14 3</p>Output: ava wel
Input: good 4 2
Output: go oo
inputFormat
The input is read from stdin and consists of three lines:
- A string \(S\) of length \(N\).
- An integer \(N\), representing the length of \(S\).
- An integer \(K\), the length of the substrings to consider.
outputFormat
Print two lines to stdout:
The first line contains the lexicographically smallest substring of length \(K\).
The second line contains the lexicographically largest substring of length \(K\).
welcometojava
14
3
ava
wel
</p>