fork download
  1. #include <bits/stdc++.h>
  2. #define VuDucNam ios_base::sync_with_stdio(false);
  3. #define Lop9a6 cin.tie(NULL);
  4. #define THCSPhamVanDong cout.tie(NULL);
  5. #define ll long long
  6. #define el cout << '\n'
  7. #define sz(a) (ll) a.size()
  8. #define all(a) a.begin(), a.end()
  9. #define fi first
  10. #define se second
  11. #define fill(a, x) memset(a, x, sizeof(a))
  12. #define file(name) \
  13.   if (fopen(name ".inp", "r")) \
  14.   { \
  15.   freopen(name ".inp", "r", stdin); \
  16.   freopen(name ".out", "w", stdout); \
  17.   }
  18. #define TIME (1.0 * clock() / CLOCKS_PER_SEC)
  19. #define RUNTIME cerr << "\nRuntime: " << TIME << "s.\n"
  20.  
  21. using namespace std;
  22.  
  23. const ll MOD = 1e9 + 7;
  24. const ll inf = LLONG_MAX;
  25.  
  26. int p,s;
  27. bool dem[11]={false};
  28.  
  29. bool check(int n)
  30. {
  31. while (n != 0)
  32. {
  33. if (dem[n % 10])
  34. return false;
  35. n /= 10;
  36. }
  37. return true;
  38. }
  39.  
  40. void solve()
  41. {
  42. cin >> p >> s;
  43.  
  44. while (s != 0)
  45. {
  46. dem[s % 10] = true;
  47. s /= 10;
  48. }
  49.  
  50. for (int i = p; i >= 1; --i)
  51. {
  52. if (check(i))
  53. {
  54. cout << i << endl;
  55. return;
  56. }
  57. }
  58. }
  59.  
  60. int main()
  61. {
  62. VuDucNam Lop9a6 THCSPhamVanDong
  63. // file();
  64. solve();
  65. RUNTIME;
  66. return 0;
  67. }
  68.  
Success #stdin #stdout #stderr 0s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Runtime: 0.004421s.