changing.cpp 304 B

1234567891011121314151617181920
  1. #include <iostream>
  2. using namespace std;
  3. const int am[] = {100, 50, 20, 10, 5, 1};
  4. int change(int& n, int i) {
  5. if (n == 0) return 0;
  6. if (i == 5) return n;
  7. int tmp = n / am[i];
  8. n -= (tmp * am[i]);
  9. return tmp + change(n, ++i);
  10. }
  11. int main() {
  12. int n;
  13. cin >> n;
  14. cout << change(n, 0);
  15. return 0;
  16. }