2017-02-12 00:31:12 -08:00
|
|
|
// Author: Rodney Shaghoulian
|
2018-07-27 16:45:56 -07:00
|
|
|
// Github: github.com/RodneyShag
|
|
|
|
|
// HackerRank: hackerrank.com/RodneyShag
|
2017-02-12 00:31:12 -08:00
|
|
|
|
2017-02-07 01:14:49 -08:00
|
|
|
import java.util.Scanner;
|
|
|
|
|
|
|
|
|
|
public class Solution {
|
|
|
|
|
public static void main(String[] args) {
|
2017-04-05 18:42:35 -05:00
|
|
|
/* Save input */
|
2017-02-07 01:14:49 -08:00
|
|
|
Scanner scan = new Scanner(System.in);
|
|
|
|
|
String s = scan.nextLine();
|
|
|
|
|
int k = scan.nextInt();
|
|
|
|
|
scan.close();
|
|
|
|
|
|
|
|
|
|
/* Create smallest and largest strings and initialize them */
|
|
|
|
|
String smallest = s.substring(0, k);
|
|
|
|
|
String largest = s.substring(0, k);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i <= s.length() - k; i++) {
|
|
|
|
|
String curr = s.substring(i, i + k);
|
|
|
|
|
if (smallest.compareTo(curr) > 0){
|
|
|
|
|
smallest = curr;
|
|
|
|
|
}
|
|
|
|
|
if (largest.compareTo(curr) < 0) {
|
|
|
|
|
largest = curr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Print results */
|
|
|
|
|
System.out.println(smallest);
|
|
|
|
|
System.out.println(largest);
|
|
|
|
|
}
|
|
|
|
|
}
|