C# ACM poj1002

排序

        public static void acm1002(string[] azx)
{ string[] a = new string[azx.Length];
for (int i = ; i < azx.Length; i++)
{
StringBuilder sb = new StringBuilder();
azx[i] = azx[i].Replace("-", "");
for (int j = ; j < azx[i].Length; j++)
{ char cr = azx[i][j];
if (cr == 'A' || cr == 'B' || cr == 'C')
{
sb.Append("");
}
else if (cr == 'D' || cr == 'E' || cr == 'F')
{
sb.Append("");
}
else if (cr == 'G' || cr == 'H' || cr == 'I')
{
sb.Append("");
}
else if (cr == 'J' || cr == 'K' || cr == 'L')
{
sb.Append("");
}
else if (cr == 'M' || cr == 'N' || cr == 'O')
{
sb.Append("");
}
else if (cr == 'P' || cr == 'R' || cr == 'S')
{
sb.Append("");
}
else if (cr == 'T' || cr == 'U' || cr == 'V')
{
sb.Append("");
}
else if (cr == 'W' || cr == 'X' || cr == 'Y')
{
sb.Append("");
}
else
{
sb.Append(cr);
}
}
a[i] = sb.ToString();
}
int[] items = new int[a.Length];
int bbbb = ;
foreach (var item in a)
{ items[bbbb] = Convert.ToInt32(item);
bbbb++; }
QSortDIY(items, , items.Length - );
// 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, );
}
else
{
dic[item]++;
}
}
foreach (var item in dic)
{
if (item.Value!=)
{
string s = item.Key.ToString();
s= s.Insert(, "-");
Console.WriteLine(s+ " " + item.Value);
}
} } public static void MPSort(int[] array)
{
int tep;
for (int i = ; i < array.Length - ; i++)
{
for (int j = ; j < array.Length - i - ; j++)
{
if (array[j] > array[j + ])
{
tep = array[j + ];
array[j + ] = 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 - );
QSortDIY(array, ie + , 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;
}
上一篇:SQL SERVER中LIKE在Char和nChar输出结果不一致解惑


下一篇:《SQL Server企业级平台管理实践》读书笔记——SQL Server中关于系统库Tempdb总结