Anon2005

cifra1

Mar 29th, 2023
773
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. ifstream in("cifra1.in");
  5. ofstream out("cifra1.out");
  6.  
  7. int main()
  8. {
  9.     int n, cif, min1 = 1000000000;
  10.     in >> n >> cif;
  11.     int put = 1;
  12.     while(put <= n)
  13.     {
  14.         int nr_nou;
  15.         nr_nou = n / put;
  16.         nr_nou = nr_nou * 10 + cif;
  17.         nr_nou = nr_nou * put + (n % put);
  18.         if(nr_nou < min1)
  19.             min1 = nr_nou;
  20.         put *= 10;
  21.     }
  22.     if(n + cif * put < min1)
  23.         min1 = n + cif * put;
  24.     out << min1;
  25.     return 0;
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment