刚写了一个,不知道是不是你的意思,参考一下吧~- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace lx
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] strs = { "a|9", "b|2", "c|1", "d|7", "a|4" };
- char[] str_char = new char[3];
- int[] num = new int[5];
- char[] strss = new char[5];
- int temp;
- char temp1;
- for (int i = 0; i < strs.Length; i++)
- {
- str_char = strs[i].ToCharArray();
- num[i] = str_char[2] - 48;
- strss[i] = Convert.ToChar(str_char[0]);
- }
- for (int j = 0; j < num.Length-1; j++)
- {
- for (int k = 0; k < num.Length - 1 - j; k++)
- {
- if (num[k] < num[k + 1])
- {
- temp = num[k];
- num[k] = num[k + 1];
- num[k + 1] = temp;
- temp1 = strss[k];
- strss[k] = strss[k + 1];
- strss[k + 1] = temp1;
- }
- }
- }
- for (int x = 0; x < num.Length; x++)
- {
- Console.Write(strss[x] + " ");
- }
- Console.ReadKey();
- }
- }
- }
复制代码 |