C#_面试

   class Program
{
static void Main(string[] args)
{
int[] arr = { , , , , };
var arry = ConvertSum(arr); int[] num = { , , , , , };
SetNum(num);
SetNum();
} //冒泡排序,目的:按从小到大排序,比较相邻两个元素,如果左边元素大于右边元素,则交换
public static int[] ConvertSum(int[] arry)
{
int temp = -;
for (int i = arry.Length; i > ; i--)
{
for (int j = ; j < i - ; j++)
{
if (arry[j] > arry[j + ])
{
temp = arry[j];
arry[j] = arry[j + ];
arry[j + ] = temp;
}
}
}
return arry;
} //1、要求是用OO的思想处理20位以内整数的乘法(解释器模式)
public static void SetNum(int[] num)
{
var temp = ;
for (int i = ; i < num.Length; i++)
{
if (i < num.Length - )
{
if (temp == )
temp += num[i] * num[i + ];
else
temp += temp * num[i];
}
}
Console.WriteLine(temp);
} //2、11个9 乘以 11个9 等于9999.........01 写个算法的
/// <summary>
// 125
//x 11
//-------
// 125
// 125
//--------
// 1375
//将乘数每位与乘数相乘,获取到一个m*n的矩阵
//将矩阵错位相加,得到输出数组
//对输出中数组进行进位运算
/// </summary>
/// <param name="num1"></param>
/// <param name="num2"></param>
public static void SetNum(string num1 = "", string num2 = "")
{
var input1 = num1.Select(i => (int)(i - ''));
var input2 = num2.Select(i => (int)(i - '')); //把num1依次和num2每位相乘,获取到一个m*n的矩阵
var rectangel = input2.Select(i => input1.Select(j => j * i).ToArray()).ToArray(); //将矩阵错位相加,得到输出数组
var result = new int[num1.Length + num2.Length];
for (int row = ; row < num2.Length; row++)
{
for (int column = ; column < num1.Length; column++)
{
result[column + row + ] += rectangel[row][column];
}
} //对输出中数组进行进位运算
for (int i = result.Length - ; i >= ; i--)
{
if (result[i] < )
continue; result[i - ] += result[i] / ;
result[i] %= ;
} Console.WriteLine(new string(result.Select(i => (char)(i += '')).ToArray()));
} }
private static string ToCapital(decimal money)
{
string str_money = money.ToString("#L#E#D#C#K#E#D#C#J#E#D#C#I#E#D#C#H#E#D#C#G#E#D#C#F#E#D#C#.0B0A");
string result = Regex.Replace(str_money, @"((?<=-|^)[^1-9]*)|((?'z'0)[0A-E]*((?=[1-9])|(?'-z'(?=[F-L.]|$))))|((?'b'[F-L])(?'z'0)[0A-L]*((?=[1-9])|(?'-z'(?=[.]|$))))", "${b}${z}");
return Regex.Replace(result, ".", m => { return "负圆空零壹贰叁肆伍陆柒捌玖空空空空空空空分角拾佰仟万億兆京垓秭穰"[m.Value[] - '-'].ToString(); });
}
上一篇:開始学习swift开发


下一篇:TFS二次开发的数据统计以PBI、Bug、Sprint等为例(一)