我正在尝试创建一个程序,可以检查哪个用户在我们的群集上同时拥有最多的作业。我有一个所有用户的列表,以及所有独特用户的单独列表。我需要为每个唯一用户创建一个变量,以存储在另一个列表中提到用户的次数。这是在C#中,任何治疗都非常感激。谢谢!
using System;
using System.IO;
using System.Text.RegularExpressions;
using System.Collections.Generic;
namespace TextScanner
{
class Niam
{
public static void Main (string[] args)
{
NameCounters TheCounters = new NameCounters();
List<string> TheNames = TheCounters.UniqueUserNames;
char[] IgnoredChars = { ' ' };
Console.WriteLine ("Enter the path to the text document you'd like to use.");
string Path = Console.ReadLine ();
string line;
StreamReader TheFile = new System.IO.StreamReader(Path);
List<string> NameCollection = new List<string>();
while ((line = TheFile.ReadLine ()) != null)
{
string[] words = line.Split(IgnoredChars, System.StringSplitOptions.RemoveEmptyEntries );
string Users = words [3];
NameCollection.Add(Users);
}
TheCounters.NameCounter (NameCollection);
NameCollection.ForEach(Console.WriteLine);
Console.WriteLine ("List of Unique Users: ");
TheNames.ForEach (Console.WriteLine);
for (int l = 0; l < TheNames.Count; l++)
{
Console.WriteLine (l);
}
}
}
}
其他课程:
using System;
using System.IO;
using System.Text.RegularExpressions;
using System.Collections.Generic;
namespace TextScanner
{
public class NameCounters
{
public List<string> UniqueUserNames = new List<string> ();
public void NameCounter (List<string> Names)
{
for (int i = 0; i < Names.Count; i++)
{
//string s = Names [i];
if (!UniqueUserNames.Contains(Names[i]))
{
UniqueUserNames.Add (Names [i]);
}
}
}
}
}