提交时间:2026-04-16 20:14:11

运行 ID: 316839

#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n == 1) { cout << 1 << endl; return 0; } queue<long long> q; for (int i = 1; i <= 9; i++) { q.push(i); } int cnt = 0; while (!q.empty()) { long long cur = q.front(); q.pop(); cnt++; if (cnt == n) { cout << cur << endl; return 0; } int d = cur % 10; for (int t = -1; t <= 1; t++) { int nd = d + t; if (nd >= 0 && nd <= 9) { long long nxt = cur * 10 + nd; q.push(nxt); } } } return 0; }