Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

c# - Find the max integer that can be obtained by permutation of numbers of an arbitrary three digit positive integer n

Find the maximum integer, that can be obtained by permutation of numbers of an arbitrary three-digit positive integer n (100<=n<=999). Example, n =165 result = 651

public static object Task2(int n)

        {
            int[] count = new int[10];
            String str = n.ToString();
            for (int i = 0; i < str.Length; i++)
                count[str[i] - '0']++;

            int result = 0, multiplier = 1;

            for (int i = 0; i <= 9; i++)
            {
                while (count[i] >= 100)
                    result = result + (i * multiplier);
                count[i]--;
                multiplier = multiplier * 10;
            }
            return result;
        }

This is the solution, but I've got an error which says Error CS0019: Operator '!=' cannot be applied to operands of type 'object' and 'int' (CS0019) (Condition.Tests)

question from:https://stackoverflow.com/questions/65645259/find-the-max-integer-that-can-be-obtained-by-permutation-of-numbers-of-an-arbitr

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...