SHARE
TWEET

Untitled

a guest May 19th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. std::vector<std::string> strings;
  6.  
  7. void add_str(size_t i, size_t j, const std::vector<std::vector<char>>& tab, std::string str = "") {
  8.     if (i + 1 == tab.size() && j + 1 == tab[0].size()) {
  9.         strings.push_back(str + tab[i][j]);
  10.     } else if (i + 1 == tab.size()) {
  11.         add_str(i, j + 1, tab, str + tab[i][j]);
  12.     } else if (j + 1 == tab[0].size()) {
  13.         add_str(i + 1, j, tab, str + tab[i][j]);
  14.     } else {
  15.         add_str(i, j + 1, tab, str + tab[i][j]);
  16.         add_str(i + 1, j, tab, str + tab[i][j]);
  17.     }
  18. }
  19.  
  20. int main() {
  21.     size_t n, m, l;
  22.     std::cin >> n >> m;
  23.     std::vector<std::vector<char>> tab(n, std::vector<char>(m));
  24.     for (size_t i = 0; i < n; ++i) {
  25.         for (size_t j = 0; j < m; ++j) {
  26.             std::cin >> tab[i][j];
  27.         }
  28.     }
  29.     add_str(0, 0, tab);
  30.     std::sort(strings.begin(), strings.end());
  31.     std::cin >> l;
  32.     std::cout << strings[l - 1] << "\n";
  33.     return 0;
  34. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top