Language: C++

#include <bits/stdc++.h>
using namespace std;

int main() {
  int K;
  cin >> K;
  cout <<lunlun(K);
  //string K_str = to_string(K);
  //cout << K_str.length();
    
}

int check_lunlun(vector<int>Lun, int keta){
  if(Lun.at(keta)+1-Lun.at(keta+1)<2 && Lun.at(keta) != 9){
    return 1;
  }
  else{
    return 0;
  }
}

int64_t lunlun(int K){
  if(K=1){
    return 1;
  }
  else{
    //999...じゃないかチェック
    string L_str = to_string(lunlun(K-1));
    int nagasa = L_str.length();
    int check9 = 0;
    for(int i=0; i<nagasa; i++){
      if(L_str.at(i) == '9'){
        check9++;
      }
    }
    if(check9==nagasa){
      return lunlun(K-1)+1;
    }
    
    vector<int> Lun(nagasa);
    for(int i=0; i<nagasa; i++){
      Lun.at(i) = stoi(L_str.at(nagasa-1-i));
    }
    
    int keta=-1;
    while(check_lunlun(Lun, keta)){
      keta++;
    }
    if(keta==nagasa-1){
      int tmp2=Lun.at(nagasa-1);
      for(int i=0; i<nagasa; i++){
        Lun.at(nagasa-1-i)=tmp2-i;
      }
    }
    else{
      Lun.at(keta)++;
    }
    
    int64_t ans = 0;
    for(int i=0; i<nagasa; i++){
      ans+=pow(10,i)*Lun.at(i);
    }
    return ans;
      
  }
  
}


  

  //int nagasa = L_str.length();
  


// int型の2次元配列(3×4要素の)の宣言
  //vector<vector<int>> data(3, vector<int>(4));
 
  // 入力 (2重ループを用いる)
  //for (int i = 0; i < 3; i++) {
    //for (int j = 0; j < 4; j++) {
      //cin >> data.at(i).at(j);
   // }
  //}


Compiler output:
a.cc: In function 'int main()':
a.cc:7:10: error: 'lunlun' was not declared in this scope
    7 |   cout <<lunlun(K);
      |          ^~~~~~
a.cc: In function 'int64_t lunlun(int)':
a.cc:42:23: error: no matching function for call to 'stoi(__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type&)'
   42 |       Lun.at(i) = stoi(L_str.at(nagasa-1-i));
      |                   ~~~~^~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/basic_string.h:4164:3: note: candidate: 'int std::__cxx11::stoi(const std::string&, std::size_t*, int)'
 4164 |   stoi(const string& __str, size_t* __idx = 0, int __base = 10)
      |   ^~~~
/usr/include/c++/14/bits/basic_string.h:4164:22: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type' {aka 'char'} to 'const std::string&' {aka 'const std::__cxx11::basic_string<char>&'}
 4164 |   stoi(const string& __str, size_t* __idx = 0, int __base = 10)
      |        ~~~~~~~~~~~~~~^~~~~
/usr/include/c++/14/bits/basic_string.h:4432:3: note: candidate: 'int std::__cxx11::stoi(const std::wstring&, std::size_t*, int)'
 4432 |   stoi(const wstring& __str, size_t* __idx = 0, int __base = 10)
      |   ^~~~
/usr/include/c++/14/bits/basic_string.h:4432:23: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type' {aka 'char'} to 'const std::wstring&' {aka 'const std::__cxx11::basic_string<wchar_t>&'}
 4432 |   stoi(const wstring& __str, size_t* __idx = 0, int __base = 10)
      |        ~~~~~~~~~~~~~~~^~~~~