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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…