• C#_面试


       class Program
        {
            static void Main(string[] args)
            {
                int[] arr = { 12, 34, 6, 22, 8 };
                var arry = ConvertSum(arr);
    
                int[] num = { 1, 2, 3, 4, 5, 6 };
                SetNum(num);
                SetNum();
            }
    
            //冒泡排序,目的:按从小到大排序,比较相邻两个元素,如果左边元素大于右边元素,则交换
            public static int[] ConvertSum(int[] arry)
            {
                int temp = -1;
                for (int i = arry.Length; i > 0; i--)
                {
                    for (int j = 0; j < i - 1; j++)
                    {
                        if (arry[j] > arry[j + 1])
                        {
                            temp = arry[j];
                            arry[j] = arry[j + 1];
                            arry[j + 1] = temp;
                        }
                    }
                }
                return arry;
            }
    
            //1、要求是用OO的思想处理20位以内整数的乘法(解释器模式)
            public static void SetNum(int[] num)
            {
                var temp = 0;
                for (int i = 0; i < num.Length; i++)
                {
                    if (i < num.Length - 1)
                    {
                        if (temp == 0)
                            temp += num[i] * num[i + 1];
                        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 = "99999999999", string num2 = "99999999999")
            {
                var input1 = num1.Select(i => (int)(i - '0'));
                var input2 = num2.Select(i => (int)(i - '0'));
    
                //把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 = 0; row < num2.Length; row++)
                {
                    for (int column = 0; column < num1.Length; column++)
                    {
                        result[column + row + 1] += rectangel[row][column];
                    }
                }
    
                //对输出中数组进行进位运算
                for (int i = result.Length - 1; i >= 0; i--)
                {
                    if (result[i] < 10)
                        continue;
    
                    result[i - 1] += result[i] / 10;
                    result[i] %= 10;
                }
    
                Console.WriteLine(new string(result.Select(i => (char)(i += '0')).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[0] - '-'].ToString(); });
            }
  • 相关阅读:
    洛谷P2831 愤怒的小鸟
    2017-10-7 清北刷题冲刺班p.m
    2017-10-7 清北刷题冲刺班a.m
    2017-10-6 清北刷题冲刺班p.m
    2017-10-5 清北刷题冲刺班p.m
    2017-10-6 清北刷题冲刺班a.m
    2017-10-5 清北刷题冲刺班a.m
    2017-10-4 清北刷题冲刺班p.m
    2017-10-4 清北刷题冲刺班a.m
    题目
  • 原文地址:https://www.cnblogs.com/ingstyle/p/6394995.html
Copyright © 2020-2023  润新知