Advertisement
KennasSticky

p52_TRICK

Jan 28th, 2022
1,053
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <cmath>
  3. #include <chrono>
  4.  
  5. using namespace std;
  6. using namespace std::chrono;
  7.  
  8. bool test(long long x)
  9. {
  10.   int arr[10] = {0};
  11.  
  12.   long long temp = x;
  13.  
  14.   string out = to_string(x);
  15.  
  16.   sort(out.begin(), out.end());
  17.  
  18.   for (int i = 2; i < 7; i++)
  19.   {
  20.     temp = x * i;
  21.  
  22.     string testing = to_string(temp);
  23.  
  24.     sort(testing.begin(), testing.end());
  25.     // check equal
  26.     if (out.compare(testing) != 0)
  27.     {
  28.       return false;
  29.     }
  30.   }
  31.  
  32.   return true;
  33. }
  34.  
  35. int main()
  36. {
  37.   // Get starting timepoint
  38.   auto start = high_resolution_clock::now();
  39.  
  40.   // PROGRAM PROCESSES FOUND HERE
  41.  
  42.   ios_base::sync_with_stdio(false);
  43.   cin.tie(NULL);
  44.  
  45.   int i = 1;
  46.  
  47.   while (!test(i*9))
  48.   {
  49.     i++;
  50.   }
  51.  
  52.   cout << (i*9) << "\n";
  53.  
  54.   // Get ending timepoint
  55.   auto stop = high_resolution_clock::now();
  56.  
  57.   // Get duration. Substart timepoints to
  58.   // get durarion. To cast it to proper unit
  59.   // use duration cast method
  60.   auto duration = duration_cast<microseconds>(stop - start);
  61.  
  62.   cout << "Time taken by function: "
  63.        << duration.count() << " microseconds" << endl;
  64.  
  65.   return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement