Language: C++

#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
char str[51];
char substr[2501][51];
bool cmp (char str1[], char str2[]) {
	if (strlen(str1) != strlen(str2)) return strlen(str1) < strlen(str2);
	int i = 0;
	while (str1[i] == str2[i]) { i++; }
	int a = str1[i] - 'a', b = str2[i] - 'a';
	return a<b;
}
int main() {
	while (scanf("%s", str) != EOF) {
		int L = strlen(str);
		int cnt = 0;
		int k;
		for (int i = 0; i < L; i++) {
			for (int j = 0; j < L - i; j++) {
				for (k = 0; k <= j; k++) {
					substr[cnt][k] = str[i + k];
				}
				 substr[cnt][k++] = 0;
				 for (int i = 0; i < cnt; i++) {
					 if (strcmp(substr[cnt], substr[i]) == 0) cnt--;
				 }
				 cnt++;
			}
		}
		sort(substr, substr + cnt,cmp);
		int m;
               scanf("%d",&m);
              printf("%s\n",substr[m-1]);
	return 0;
   }
}

Compiler output:
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_algo.h: In instantiation of 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = char (*)[51]; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(char*, char*)>]':
/usr/include/c++/14/bits/stl_algo.h:1817:25:   required from 'void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = char (*)[51]; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(char*, char*)>]'
 1817 |           std::__insertion_sort(__first, __first + int(_S_threshold), __comp);
      |           ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1908:31:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = char (*)[51]; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(char*, char*)>]'
 1908 |           std::__final_insertion_sort(__first, __last, __comp);
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4805:18:   required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = char (*)[51]; _Compare = bool (*)(char*, char*)]'
 4805 |       std::__sort(__first, __last, __gnu_cxx::__ops::__iter_comp_iter(__comp));
      |       ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:31:7:   required from here
   31 |                 sort(substr, substr + cnt,cmp);
      |                 ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1780:17: error: array must be initialized with a brace-enclosed initializer
 1780 |                 __val = _GLIBCXX_MOVE(*__i);
      |                 ^~~~~
/usr/include/c++/14/bits/stl_algo.h:1782:24: error: invalid array assignment
 1782 |               *__first = _GLIBCXX_MOVE(__val);
      |                        ^
In file included from /usr/include/c++/14/bits/stl_algo.h:61:
/usr/include/c++/14/bits/stl_heap.h: In instantiation of 'void std::__make_heap(_RandomAccessIterator, _RandomAccessIterator, _Compare&) [with _RandomAccessIterator = char (*)[51]; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(char*, char*)>]':
/usr/include/c++/14/bits/stl_algo.h:1593:23:   required from 'void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = char (*)[51]; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(char*, char*)>]'
 1593 |       std::__make_heap(__first, __middle, __comp);
      |       ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1868:25:   required from 'void std::__partial_sort(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = char (*)[51]; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(char*, char*)>]'
 1868 |       std::__heap_select(__first, __middle, __last, __comp);
      |       ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1884:27:   required from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = char (*)[51]; _Size = long int; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(char*, char*)>]'
 1884 |               std::__partial_sort(__first, __last, __last, __comp);
      |               ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1905:25:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = char (*)[51]; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(char*, char*)>]'
 1905 |           std::__introsort_loop(__first, __last,
      |           ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
 1906 |                                 std::__lg(__last - __first) * 2,
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1907 |                                 __comp);
      |                                 ~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4805:18:   required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = char (*)[51]; _Compare = bool (*)(char*, char*)]'
 4805 |       std::__sort(__first, __last, __gnu_cxx::__ops::__iter_comp_iter(__comp));
      |       ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:31:7:   required from here
   31 |                 sort(substr, substr + cnt,cmp);
      |                 ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_heap.h:355:22: error: array must be initialized with a brace-enclosed initializer
  355 |           _ValueType __value = _GLIBCXX_MOVE(*(__first + __parent));
      |                      ^~~~~~~
/usr/include/c++/14/bits/stl_heap.h: In instantiation of 'void std::__pop_heap(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare&) [with _RandomAccessIterator = char (*)[51]; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(char*, char*)>]':
/usr/include/c++/14/bits/stl_algo.h:1596:19:   required from 'void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = char (*)[51]; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(char*, char*)>]'
 1596 |           std::__pop_heap(__first, __middle, __i, __comp);
      |           ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1868:25:   required from 'void std::__partial_sort(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = char (*)[51]; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(char*, char*)>]'
 1868 |       std::__heap_select(__first, __middle, __last, __comp);
      |       ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1884:27:   required from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = char (*)[51]; _Size = long int; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(char*, char*)>]'
 1884 |               std::__partial_sort(__first, __last, __last, __comp);
      |               ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1905:25:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = char (*)[51]; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(char*, char*)>]'
 1905 |           std::__introsort_loop(__first, __last,
      |           ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
 1906 |                                 std::__lg(__last - __first) * 2,
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1907 |                                 __comp);
      |                                 ~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4805:18:   required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = char (*)[51]; _Compare = bool (*)(char*, char*)]'
 4805 |       std::__sort(__first, __last, __gnu_cxx::__ops::__iter_comp_iter(__comp));
      |       ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:31:7:   required from here
   31 |                 sort(substr, substr + cnt,cmp);
      |                 ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_heap.h:262:18: error: array must be initialized with a brace-enclosed initializer
  262 |       _ValueType __value = _GLIBCXX_MOVE(*__result);
      |                  ^~~~~~~
/usr/include/c++/14/bits/stl_heap.h:263:17: error: invalid array assignment
  263 |       *__result = _GLIBCXX_MOVE(*__first);
      |                 ^