Computer Science, asked by engvicky786, 4 months ago

Given an integer number n, count the number of
digits you can rotate to get the minimal integer,
We can rotate the following numbers only.
2--5
6 --9
Example:
Input - 9255
Output - 6222

Explanation
We can change 9 to 6 and 5's to 2 to get 6222 to get
the minimal integer

Answers

Answered by dreamrob
2

Program :

#include<iostream>

#include<cmath>

using namespace std;

int main()

{

int n,N=0,c=0,count=0;

cout<<"Enter Number : ";

cin>>n;

while(n!=0)

{

 int d = n%10;

 if(d == 9)

 {

  d = 6;

  count++;

 }

 if(d == 5)

 {

  d = 2;

  count++;

 }

 d = d * pow(10,c++);

 N = N + d;

 n = n/10;

}

cout<<"Total number of digits rotated : "<<count<<endl;

cout<<"Minimal number after rotation : "<<N;

return 0;

}

Output:

Enter Number : 9255

Total number of digits rotated : 3

Minimal number after rotation : 6222

Similar questions