egogoboy

A div B

Sep 14th, 2022
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. #include<string>
  4. #define all(container) container.begin(), container.end()
  5. #define fors(counter, start, finish) for (int counter = start; counter < finish; ++counter)
  6. #define forb(counter, start, finish) for (int counter = start; counter >= finish; --counter)
  7. #define vec(type) std::vector<type>
  8. #define dvec(type) std::vector<std::vector<type>>
  9.  
  10. int main() {
  11.  
  12.     std::ifstream fin("input.txt");
  13.     std::string s;
  14.     int n;
  15.     fin >> s >> n;
  16.  
  17.     int i = 0, a = 0;
  18.     std::string ans;
  19.     while (i < s.size()) {
  20.         bool f = false;
  21.         while (a < n && i < s.size()) {
  22.             a *= 10; a += s[i] - '0';
  23.             ++i;
  24.             if (f)
  25.                 ans.push_back('0');
  26.             f = true;
  27.         }
  28.         ans.push_back(a / n + '0');
  29.         a %= n;
  30.     }
  31.     int idx = 0;
  32.     while (ans[idx] == '0')
  33.         idx++;
  34.  
  35.     std::cout << ans.size() << std::endl;
  36.     std::cout << ans.substr(idx, ans.size() - idx) << std::endl;
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment