/*5.1 随机从控制台输入一串字符,统计各字符出现的次数。*/
using System;
class countstring
{
static void Main()
{
int n=0;
int p=1;
Console.Write("请输入任意字符串:");
string s =Console.ReadLine();
n =s.Length;//获取索引函数的边界
int l = n;
char [] array2=new char[n];//定义char型数组并初始化
char[] array1 = new char[n];
int [] count = new int[n];//
for (int i = 0; i < n; i++)
{
array2[i] = s[i];//把字符串赋值给字符数组
Console.Write("第{0}个为:{1}\t",i+1,array2[i] );//输出字符数组的每一个值
}
Console.WriteLine();
for (int j =0; j < n; j++)
{
p = 1;
for (int k = j + 1; k < n; k++)
{
if (array2[j] == array2[k])
{
l--;
array1[j] = array2[k];
p++;
count[j] = p;
if (count[j] < count[k])
count[j] = count[k];
}
else
continue;
}
Console.WriteLine("你输入的字符串里{0}出现的次数是:{1}",array2[j],count[j]+1);
}
Console.Read();
}
}
帮我看看我写的这个程序,就是红色部分不太合乎题意,看看能怎么改!!