题目大意:给定一个闭区间,问这个区间内有没有满足各数位数字不相等的数,有的话输出任意一个,没有的话输出 -1.
#include <bits/stdc++.h> #include <bitset> using namespace std; #define mp(x, y) make_pair(x,y) #define mset(a, n) memset(a, n, sizeof(a)) #define forn(i, n) for (int i = 0; i < (n); i++) #define forab(i, a, b) for (int i = (a); i <= (b); i++) #define forba(i, b, a) for (int i = (b); i >= (a); i--) #define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0) #define INF 0x3f3f3f3f #define ld long double #define ll long long #define ls(x) 2 * (x) #define rs(x) (2 * (x) + 1) #define lowbit(x) (x & -(x)) #define endl ‘\n‘ #define fi first #define se second const int N = 1e5 + 5; bool vis[10]; int main() { fast; int l, r; cin >> l >> r; bool flag = 0; for (int x = l; x <= r; ++x) { mset(vis, 0); int cnt = 0, num = 0; int t = x; while(t) { int y = t % 10; if (!vis[y]) { vis[y] = 1; ++cnt; } ++num; t /= 10; } if (cnt == num) { flag = 1; cout << x << endl; break; } } if (!flag) cout << "-1" << endl; }
原文地址:https://www.cnblogs.com/zssst/p/11610826.html
时间: 2024-10-04 12:26:42