static void Main(string[] args)
{
Console.WriteLine("请输入整数或浮点数");
string content = Console.ReadLine();
decimal dt = 0;
try
{
var bbts = true;
dt = decimal.Parse(content);
if (dt >100000000)
{
Console.WriteLine("请输入小于1亿的数");
bbts = false;
}
if (bbts)
{
string[] str = new string[] { "个", "十", "百", "千", "万", "十万", "百万", "千万", "亿" };
var bbt = dt.ToString().Split('.');
Console.WriteLine(GetRead(str, bbt));
}
}
catch (Exception ex)
{
Console.WriteLine("输入错误,请输入整数或浮点数");
}
}
public static string GetRead(string[] str, string[] num)
{
string content = "";
for (int i = 0; i < num.Length; i++)
{
content+= i == 0 ? "整数部分:" + num[i] + "\n" : "小数部分:" + num[i]+"\n";
var num2 = num[i].ToCharArray();
var count = 0;
for (int a = 0; a < num2.Length; a++)
{
if (int.Parse(num2[a].ToString()) == OrderByMax(num2))
{
count = a;
}
content += i == 0 ? (str[num2.Length-a-1] + "位:" + num2[a] + "\n") : (str[a]+"分位:" + num2[a] + "\n");
}
content += i == 0 ? "最大数:" + OrderByMax(num2) + "\n" : "最大数:" + OrderByMax(num2) + "\n";
content += i == 0 ? "位置:" + str[num2.Length - count - 1] + "\n" : "位置:" + str[count] + "分位\n";
content += i == 0 ? "" : "舍弃小数部位最大的数后,该小数为" + num[0] + "." + num[1].Split(char.Parse(OrderByMax(num2).ToString()))[0] + "\n";
}
return content;
}
public static int OrderByMax(char[] intArrays)
{
int [] intArray =new int [intArrays.Length] ;
for (int c = 0; c < intArrays.Length; c++)
{
intArray[c] =int.Parse(intArrays[c].ToString());
}
int temp = 0;
for (int i = 0; i < intArray.Length; i++)
{
for (int j = 0; j < intArray.Length - 1 - i; j++)
if (intArray[j] > intArray[j + 1])
{
temp = intArray[j];
intArray[j] = intArray[j + 1];
intArray[j + 1] = temp;
}
}
return intArray[intArray.Length - 1];
}