示例#1
0
 public DataPair(DataPair dataPair)
 {
     DataSet  = dataPair.DataSet;
     DataKey  = dataPair.DataKey;
     DataSize = dataPair.DataSize;
 }
示例#2
0
        static void Main(string[] args)
        {
            Dictionary <string, List <DataPair> > dataSets = new Dictionary <string, List <DataPair> >();
            List <DataPair> cache = new List <DataPair>();

            Regex dataCapture = new Regex(@"^([^->|\s]+)$|^([^->|\s]+)\s->\s(\d+)\s\|\s([^->|\s]+)$");

            while (true)
            {
                //Get Input
                string dataInput = Console.ReadLine();
                if (dataInput == "thetinggoesskrra")
                {
                    break;
                }

                Match dataMatch = dataCapture.Match(dataInput);

                if (dataMatch.Groups[1].Value != string.Empty)   //Add a new dataSet
                {
                    dataSets[dataMatch.Groups[1].ToString()] = new List <DataPair>();

                    //Add pairs from cache after new dataSet is added
                    for (int i = 0; i < cache.Count; i++)
                    {
                        if (dataSets.ContainsKey(cache[i].DataSet))
                        {
                            dataSets[cache[i].DataSet].Add(cache[i]);
                            cache[i] = null; //Null added pairs to prepare for removal from cache
                        }
                    }

                    //Remove pairs already added to dataSet after having been nulled
                    cache = cache.Where(data => data != null).ToList();
                }
                else   //Add a new DataPair
                {
                    string   dataKey     = dataMatch.Groups[2].ToString();
                    string   dataSize    = dataMatch.Groups[3].ToString();
                    string   dataSetName = dataMatch.Groups[4].ToString();
                    DataPair newDataPair = new DataPair(dataSetName, dataKey, int.Parse(dataSize));

                    if (dataSets.ContainsKey(dataSetName))
                    {
                        dataSets[dataSetName].Add(newDataPair);
                    }
                    else
                    {
                        cache.Add(newDataPair);
                    }
                }
            }

            //Find largest Data Set
            List <DataPair> largestDataSet = new List <DataPair>();

            foreach (var dataSet in dataSets)
            {
                List <DataPair> thisDataSet = dataSet.Value;
                if (SumSetSize(thisDataSet) > SumSetSize(largestDataSet))
                {
                    largestDataSet = thisDataSet;
                }
            }

            //Print the Results
            if (largestDataSet.Count == 0)
            {
                return;
            }
            else
            {
                Console.WriteLine($"Data Set: {largestDataSet[0].DataSet}, Total Size: {SumSetSize(largestDataSet)}");
                foreach (var item in largestDataSet)
                {
                    Console.WriteLine($"$.{item.DataKey}");
                }
            }
        }