2 solutions

  • 0
    @ 2025-4-21 16:35:51
    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        int res;
        cin>>res;
        int a=res/100;
        int b=res/10%10;
        int c=res%10;
        int cnt=0;
        if(res==495)
        {
            cout<<'0';
            return 0;
        }
        do
        {
            a=res/100;
            b=res/10%10;
            c=res%10;
            int x1,x2,x3,x4,x5,x6;
            x1=a*100+b*10+c*1;
            x2=a*100+c*10+b*1;
            x3=b*100+a*10+c*1;
            x4=b*100+c*10+a*1;
            x5=c*100+a*10+b*1;
            x6=c*100+b*10+a*1;
            int maxv;
            maxv=max({x1,x2,x3,x4,x5,x6});
            int minv;
            minv=min({x1,x2,x3,x4,x5,x6});
            res=maxv-minv;
            if(res==495)
            {
                cnt++;
                break;
            }
            else
            {
                cnt++;
                continue;
            }
        }while(1);
        cout<<cnt;
        return 0;
    }
    
    • 0
      @ 2025-4-21 16:33:44
      #include<bits/stdc++.h>
      using namespace std;
      int main()
      {
      	int n;
      	cin>>n;
      	int cnt=0;
      	while(n!=495)
      	{
      		
      		int g=n%10,s=n/10%10,b=n/100%10;
      		if(g<s) swap(g,s);
      		if(g<b) swap(g,b);
      		if(s<b) swap(s,b);
      		cnt++;
      		int a1=g*100+s*10+b,a2=b*100+s*10+g;
      		n=a1-a2;
      	}
      	cout<<cnt;
      	return 0;
      }
      
      
      • 1

      Information

      ID
      1178
      Time
      1000ms
      Memory
      256MiB
      Difficulty
      9
      Tags
      (None)
      # Submissions
      15
      Accepted
      3
      Uploaded By