C# ACM poj1002

排序 

        public static void acm1002(string[] azx)
        {

            string[] a = new string[azx.Length];
            for (int i = 0; i < azx.Length; i++)
            {
                StringBuilder sb = new StringBuilder();
                azx[i] = azx[i].Replace("-", "");
                for (int j = 0; j < azx[i].Length; j++)
                {

                    char cr = azx[i][j];
                    if (cr == 'A' || cr == 'B' || cr == 'C')
                    {
                        sb.Append("2");
                    }
                    else if (cr == 'D' || cr == 'E' || cr == 'F')
                    {
                        sb.Append("3");
                    }
                    else if (cr == 'G' || cr == 'H' || cr == 'I')
                    {
                        sb.Append("4");
                    }
                    else if (cr == 'J' || cr == 'K' || cr == 'L')
                    {
                        sb.Append("5");
                    }
                    else if (cr == 'M' || cr == 'N' || cr == 'O')
                    {
                        sb.Append("6");
                    }
                    else if (cr == 'P' || cr == 'R' || cr == 'S')
                    {
                        sb.Append("7");
                    }
                    else if (cr == 'T' || cr == 'U' || cr == 'V')
                    {
                        sb.Append("8");
                    }
                    else if (cr == 'W' || cr == 'X' || cr == 'Y')
                    {
                        sb.Append("9");
                    }
                    else
                    {
                        sb.Append(cr);
                    }
                }
                a[i] = sb.ToString();
            }
            int[] items = new int[a.Length];
            int bbbb = 0;
            foreach (var item in a)
            {

                items[bbbb] = Convert.ToInt32(item);
                bbbb++;
                
            }           
            QSortDIY(items, 0, items.Length - 1);
           // Console.WriteLine(string.Join(",", items));
            Dictionary<int, int> dic = new Dictionary<int, int>();
            foreach (var item in items)
            {
                if (!dic.ContainsKey(item))
                {
                    dic.Add(item, 1);
                }
                else
                {
                    dic[item]++;
                }
            }
            foreach (var item in dic)
            {
                if (item.Value!=1)
                {
                    string s = item.Key.ToString();
                    s= s.Insert(3, "-");
                    Console.WriteLine(s+ " " + item.Value);
                }
            }
        
        }

        public static void MPSort(int[] array)
        {
            int tep;
            for (int i = 0; i < array.Length - 1; i++)
            {
                for (int j = 0; j < array.Length - i - 1; j++)
                {
                    if (array[j] > array[j + 1])
                    {
                        tep = array[j + 1];
                        array[j + 1] = array[j];
                        array[j] = tep;
                    }
                }
            }
        }

        public static void QSortDIY(int[] array, int low, int high)
        {
            if (low >= high)
            {
                return;
            }
            int ie = QSortUnit(array, low, high);
            QSortDIY(array, low, ie - 1);
            QSortDIY(array, ie + 1, high);
        }
        private static int QSortUnit(int[] array, int low, int high)
        {
            int key = array[low];
            while (low < high)
            {
                while (array[high] >= key && high > low)
                {
                    --high;
                }
                array[low] = array[high];
                while (array[low] <= key && high > low)
                {

                    ++low;
                }
                array[high] = array[low];
            }
            array[low] = key;
            return high;
        }

 

转载于:https://www.cnblogs.com/DhyDream/p/4335248.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ACM 输入输出主要是指在ACM编程竞赛中,处理输入和输出数据的方式。 在C#中,处理ACM输入输出通常需要使用Console.ReadLine()和Console.WriteLine()方法来获取输入和输出数据。通过使用这些方法,我们可以读取标准输入流中的数据并将结果输出到标准输出流中。 根据引用,在处理ACM输出时,如果题目要求在输出样例中每组样例之间有特定的分隔符(如换行或空格),我们可以在输出每组样例后判断是否是最后一组,如果不是则输出相应的分隔符,如果是最后一组则直接结束。 根据引用,在处理ACM输出时,我们可以使用一个布尔变量来判断是否是第一组输出。如果是第一组,则输出后将布尔变量设置为false;则,输出每组样例前先输出分隔符,并输出每组样例。 以下是一个示例代码,演示了如何使用C#处理ACM输入输出: using System; using System.Collections.Generic; using System.Linq; namespace ACMExample { class Program { static void Main() { int n = int.Parse(Console.ReadLine()); bool isFirst = true; while (n-- > 0) { List<int> a = new List<string>(Console.ReadLine().Split()).ConvertAll(i => int.Parse(i)); if (isFirst) { isFirst = false; } else { Console.WriteLine(); } Console.WriteLine(a + a); } Console.ReadKey(); } } } 在这个示例中,我们首先读取一个整数n,表示有多少组输入。然后,使用一个布尔变量isFirst来判断是否是第一组输出。接下来的while循环中,我们使用Console.ReadLine()方法读取每组输入数据,并使用Console.WriteLine()方法输出每组数据的运算结果。最后,使用Console.ReadKey()方法来等待用户按下任意键以结束程序。 希望以上的解答能帮助到您。如果还有其他问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值