Advertisement
Guest User

Untitled

a guest
Sep 11th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #include <cmath>
  2. #include <string>
  3. #include <cstring>
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8. int ans;
  9. int s;
  10. string ts;
  11. bool ok[10];
  12.  
  13. int main(void) {
  14. ios_base::sync_with_stdio(false);
  15. cin.tie(nullptr);
  16.  
  17. cin >> s;
  18. ts = to_string(s);
  19. int n;
  20. cin >> n;
  21. memset(ok, true, sizeof(ok));
  22. for (int i = 0; i < n; i++) {
  23. int x;
  24. cin >> x;
  25. ok[x] = false;
  26. }
  27. ans = abs(100 - s);
  28.  
  29. for (int i = 0; i <= 1000000; i++) {
  30. string tmp = to_string(i);
  31. bool isok = true;
  32. for (int j = 0; j < tmp.size(); j++) {
  33. int num = tmp[j] - '0';
  34. if (!ok[num]) {
  35. isok = false;
  36. break;
  37. }
  38. }
  39. if (isok) {
  40. int cnt = tmp.size() + abs(s - i);
  41. if (ans > cnt) {
  42. ans = cnt;
  43. }
  44. }
  45. }
  46.  
  47. cout << ans << '\n';
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement