思路 : 可看成统计字符个数,然后根据字符个数的多少进行降序排序 ,最的数跟26相乘 其次大的数跟25 依次递减
------------------------------------------------------------------
using System;
using System.Collections.Generic;using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace S
{
class Program
{
static void Main(string[] args)
{
string s = Console.ReadLine();
int[] a = new int [32];
int i, j;
for (i = 0; i < a.Length; i++)
{
a[i] = 0;
}
s = s.ToLower();
for ( i = 0; i < s.Length; i++)
{
j = s[i] - 'a';
a[j] = a[j] + 1;
}
//我写的冒泡排序有问题
#region
//for (i = 0; i < s.Length; i++)
//{
// for (j = i; j <= s.Length; j++)
// {
// int temp = 0;
// if (a[i] < a[j])
// {
// temp = a[i];
// a[i] = a[j];
// a[j] = temp;
// }
// }
//}
#endregion
//Array.Sort(a);
//Array.Reverse(a);
int sum = 0;
int k = 26;
for ( i = 0; i <a.Length; i++)
{
sum = sum + a[i] * k;
k--;
}
Console.WriteLine(sum);
}
}
}
本文介绍了一种通过统计字符串中字符出现频率并利用特定排序算法进行处理的方法。该方法首先将输入字符串转换为小写形式,接着统计每个字母的出现次数,并按一定规则计算最终得分。虽然文中使用的排序算法存在问题,但此过程为理解字符频率处理提供了良好示例。
724

被折叠的 条评论
为什么被折叠?



