Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  //Compiler version g++ 6.3.0
  4.  
  5.  void findCuts(int n, int &amountOfCuts, int &smallest) {
  6.     bool isSmallest = false;
  7.     for (int i = 0; i <= 9; i++) {
  8.         int newN = n;
  9.        
  10.         while (newN != 0) {
  11.             int rem = newN % 10;
  12.            
  13.             if (rem == i) {
  14.                 if (!isSmallest) {
  15.                     isSmallest = true;
  16.                     smallest = rem;
  17.                 } else if (rem != smallest) {
  18.                     amountOfCuts += 1;
  19.                     break;
  20.                 }
  21.             }
  22.            
  23.             newN /= 10;
  24.         }
  25.     }
  26.  }
  27.  
  28.  int main() {
  29.     int n = 911131;
  30.     int smallest, amountOfCuts;
  31.     smallest = amountOfCuts = 0;
  32.    
  33.     findCuts(n, amountOfCuts, smallest);
  34.     cout << "Smallest: " << smallest << endl;
  35.     cout << "Amount: " << amountOfCuts;
  36.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement