Advertisement
kdzhr

DISCSHOP

Feb 20th, 2020
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. // OK brute force DISCSHOP https://www.codechef.com/problems/DISCSHOP
  2.  
  3. # include <iostream>
  4. # include <cmath>
  5. using namespace std;
  6.  
  7. int main() {
  8.     size_t t;
  9.     cin >> t;
  10.     for (size_t i = 0; i < t; i++) {
  11.         size_t n;
  12.         cin >> n;
  13.         size_t res = n;
  14.         size_t k = 1;
  15.         int32_t count = to_string(n).length();
  16.         while (count -- > 0) {
  17.             size_t left = n / (k * 10);
  18.             size_t right = n % k;
  19.             size_t cur = left * k + right;
  20.             k *= 10;
  21.             res = min(res, cur);
  22.         }
  23.         cout << res << '\n';
  24.     }
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement