C# IEnumerable<;字符串>;阵列滤波

C# IEnumerable<;字符串>;阵列滤波,c#,C#,考虑输入数据(在stdin上),其中包含关于公司当前版本的每个产品正在使用各种库的哪些版本的信息: Mail Server, Authentication Library, v6 Video Call Server, Authentication Library, v7 Mail Server, Data Storage Library, v10 Chat Server, Data Storage Library, v11 Mail Server, Search Library, v6 Chat

考虑输入数据(在stdin上),其中包含关于公司当前版本的每个产品正在使用各种库的哪些版本的信息:

Mail Server, Authentication Library, v6
Video Call Server, Authentication Library, v7
Mail Server, Data Storage Library, v10
Chat Server, Data Storage Library, v11
Mail Server, Search Library, v6
Chat Server, Authentication Library, v8
Chat Server, Presence Library, v2
Video Call Server, Data Storage Library, v11
Video Call Server, Video Compression Library, v3
每行输入由3个逗号分隔的字段组成。 第一个字段是产品名称, 第二个字段是库名称,并且 第三个字段是该产品使用的库版本号

上面给出的示例表明,邮件服务器使用验证库的v6版本,视频呼叫服务器使用验证库的v7版本,邮件服务器也使用数据存储库的v10版本,依此类推。在本程序中,假设所有版本号的形式为v,其中表示一个或多个十进制数字。

public static List<String> processData(IEnumerable<string> lines)
        {
            /*                  
             * Here I have to process `array` as indicated
             * in the question. At the end, I need to return a List containing
             * the appropriate values                
             */
            List<String> retVal = new List<String>();
            return retVal;
        }

static void Main(string[] args)
        {
            try
            {
                String line;
                var inputLines = new List<String>();
                while ((line = Console.ReadLine()) != null)
                {
                    line = line.Trim();
                    if (line != "")
                        inputLines.Add(line);
                }
                var retVal = processData(inputLines);
                foreach (var res in retVal)
                    Console.WriteLine(res);
            }
            catch (IOException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
因为邮件服务器使用的是旧版本的身份验证库和数据存储库,而视频呼叫服务器使用的是旧版本的身份验证库。请仔细阅读示例,以准确了解您希望做什么

谢谢,

这可能会对您有所帮助

string[] arr;
int version;
Dictionary<string, int> dctMax = new Dictionary<string, int>();
foreach (string item in inputLines)
{
    arr = item.Split(',');
    version = int.Parse(arr[2].Replace("v", ""));
    KeyValuePair<string, int> kvp = dctMax.FirstOrDefault(r => r.Key.Equals(arr[1]));
    if (string.IsNullOrEmpty(kvp.Key))
    {
        dctMax.Add(arr[1], version);
    }
    else
    {
        if (kvp.Value < version)
        {
            dctMax[kvp.Key] = version;
        }
    }
}

foreach (string item in inputLines)
{
    arr = item.Split(',');
    version = int.Parse(arr[2].Replace("v", ""));
    dctMax.TryGetValue(arr[1], out int maxVal);
    if (version < maxVal)
    {
        Console.WriteLine(item + " is old. Latest version is : " + maxVal);
    }
}
string[]arr;
int版本;
Dictionary dctMax=新字典();
foreach(输入行中的字符串项)
{
arr=项目拆分(',');
version=int.Parse(arr[2]。替换(“v”,替换为“);
KeyValuePair kvp=dctMax.FirstOrDefault(r=>r.Key.Equals(arr[1]);
if(string.IsNullOrEmpty(kvp.Key))
{
dctMax.Add(arr[1],版本);
}
其他的
{
如果(kvp.Value<版本)
{
dctMax[kvp.Key]=版本;
}
}
}
foreach(输入行中的字符串项)
{
arr=项目拆分(',');
version=int.Parse(arr[2]。替换(“v”,替换为“);
dctMax.TryGetValue(arr[1],out int maxVal);
如果(版本
这可能会对您有所帮助

string[] arr;
int version;
Dictionary<string, int> dctMax = new Dictionary<string, int>();
foreach (string item in inputLines)
{
    arr = item.Split(',');
    version = int.Parse(arr[2].Replace("v", ""));
    KeyValuePair<string, int> kvp = dctMax.FirstOrDefault(r => r.Key.Equals(arr[1]));
    if (string.IsNullOrEmpty(kvp.Key))
    {
        dctMax.Add(arr[1], version);
    }
    else
    {
        if (kvp.Value < version)
        {
            dctMax[kvp.Key] = version;
        }
    }
}

foreach (string item in inputLines)
{
    arr = item.Split(',');
    version = int.Parse(arr[2].Replace("v", ""));
    dctMax.TryGetValue(arr[1], out int maxVal);
    if (version < maxVal)
    {
        Console.WriteLine(item + " is old. Latest version is : " + maxVal);
    }
}
string[]arr;
int版本;
Dictionary dctMax=新字典();
foreach(输入行中的字符串项)
{
arr=项目拆分(',');
version=int.Parse(arr[2]。替换(“v”,替换为“);
KeyValuePair kvp=dctMax.FirstOrDefault(r=>r.Key.Equals(arr[1]);
if(string.IsNullOrEmpty(kvp.Key))
{
dctMax.Add(arr[1],版本);
}
其他的
{
如果(kvp.Value<版本)
{
dctMax[kvp.Key]=版本;
}
}
}
foreach(输入行中的字符串项)
{
arr=项目拆分(',');
version=int.Parse(arr[2]。替换(“v”,替换为“);
dctMax.TryGetValue(arr[1],out int maxVal);
如果(版本
或者,创建一个包含ServerName、LibraryName、版本属性的对象更加优雅。或者,创建一个包含ServerName、LibraryName、版本属性的对象更加优雅。