Archived
1
0
This repository has been archived on 2026-03-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
SomeLab/CS/lab10/10_4/Program.cs
2026-03-19 19:39:01 +08:00

25 lines
884 B
C#

namespace _10_4
{
internal class Program
{
static void Main(string[] args)
{
string text = @"The quick brown fox jumps over the lazy dog." +
@"An apple a day keeps the doctor away." +
@"Can a fox and a dog be friends?";
Console.WriteLine(text);
string searchTerm = "the";
string[] source = text.ToLower().Split(new char[] { '.', ' ','!','?','.' }, StringSplitOptions.RemoveEmptyEntries);
int wordCount = 0;
foreach (string s in source)
{
if (s.CompareTo(searchTerm)==0)
{
wordCount++;
}
}
Console.WriteLine("单词{0}一共出现{1}次,频率{2:#0.##%}",searchTerm,wordCount,wordCount/(double)source.Length);
}
}
}