当前位置: 首页>>代码示例>>C#>>正文


C# Dictionary.Max方法代码示例

本文整理汇总了C#中Dictionary.Max方法的典型用法代码示例。如果您正苦于以下问题:C# Dictionary.Max方法的具体用法?C# Dictionary.Max怎么用?C# Dictionary.Max使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Dictionary的用法示例。


在下文中一共展示了Dictionary.Max方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

    private static void Main(string[] args)
    {
        string[] strings = new string[int.Parse(Console.ReadLine())];
        for (int i = 0; i < strings.Length; i++)
        {
            strings[i] = Console.ReadLine();
        }

        Dictionary<string, int> Areas = new Dictionary<string, int>();

        foreach (var item in strings)
        {
            if (Areas.ContainsKey(item))
            {
                Areas[item]++;
            }
            else
            {
                Areas.Add(item, 1);
            }
        }

        for (int i = 0; i < Areas.Max(x => x.Value); i++)
        {
            Console.WriteLine(Areas.Aggregate((x, y) => y.Value > x.Value ? y : x).Key);
        }
    }
开发者ID:EBojilova,项目名称:SoftUni-3,代码行数:27,代码来源:LongestAreaInArray.cs

示例2: Main

        public static void Main()
        {
            List<int> numbers = new List<int>() { 3, 4, 4, 2, 3, 3, 3, 3, 3, 2, 5, 3, 5, 6, 3, 5, 3 };
            Dictionary<int, int> occures = new Dictionary<int, int>();
            foreach (var item in numbers)
            {
                if (occures.ContainsKey(item))
                {
                    occures[item]++;
                }
                else
                {
                    occures.Add(item, 1);
                }
            }

            int maxOccures = occures.Max(x => x.Value);
            int countAllElements = numbers.Count;
            if (maxOccures >= countAllElements / 2 + 1)
            {
                Console.WriteLine("majorant is: {0}", maxOccures);
            }
            else
            {
                Console.WriteLine("majorant not exist");
            }
        }
开发者ID:BorislavIvanov,项目名称:Telerik_Academy,代码行数:27,代码来源:FindMajorantOfArray.cs

示例3: GetBestDays

        public static string GetBestDays(int suggestionId)
        {
            List<JoinedUser> users = GetJoinedUsers(suggestionId);

            Dictionary<String, int> votesPerDay = new Dictionary<string, int>();

            foreach (var user in users)
            {
                String[] days = user.Weekdays.Split(',');
                foreach (var day in days)
                {
                    int count;
                    if (votesPerDay.TryGetValue(day, out count))
                        votesPerDay[day] = count + 1;
                    else
                        votesPerDay.Add(day, 1);
                }
            }

            int highest = votesPerDay.Max(kvp => kvp.Value);
            var values = "";

            foreach (var kvp in votesPerDay)
            {
                if (kvp.Value == highest)
                    values += kvp.Key + ", ";
            }

            if (values.Length >= 2)
                values = values.Remove(values.Length - 2, 2);

            return values;
        }
开发者ID:steffenrs,项目名称:Find-My-Sports-Mate,代码行数:33,代码来源:SuggestionBusiness.cs

示例4: VisaData

        public void VisaData(IList<AktivPeriod> perioder)
        {
            panel1.Controls.Clear();

            var lista = new Dictionary<DateTime, double>();

            foreach (var dag in perioder.Select(o => o.Starttid.Date).Distinct())
            {
                var summeradDag = dag;
                lista.Add(dag,
                          perioder.Where(o => o.Starttid.Date.Equals(summeradDag)).Sum(o => o.Tidsmängd.TotalMinutes));
            }

            if (!lista.Any()) return;

            var max = lista.Max(o => o.Value);
            var xposition = 10;
            foreach (var d in lista)
            {
                var stapel = new Dagstapel
                                 {
                                     Height = panel1.Height - 20,
                                     Top = 10,
                                     Left = xposition
                                 };

                stapel.VisaUppgifter(d.Key, d.Value, max);
                xposition += stapel.Width;
                panel1.Controls.Add(stapel);
            }
        }
开发者ID:fredrikakesson,项目名称:Activity-Monitor,代码行数:31,代码来源:Diagramarea.cs

示例5: Calc

    private string Calc(List<string> lst)
    {
        var str = "";
        foreach (var item in lst)
        {
            var dict2 = new Dictionary<int, float>();
            for (int i = 0; i < CodeArray.Length; i++)
            {
                var match = new MatchsMaker(item, CodeArray[i]);
                dict2.Add(i, match.Score);
            }

            var idx = dict2.First(p => p.Value == dict2.Max(x => x.Value)).Key;
            switch (idx)
            {
                case 10:
                    idx = 1;
                    break;
                case 11:
                case 12:
                    idx = 0;
                    break;
                default:
                    break;
            }

            str += idx;
        }
        return str;
    }
开发者ID:henrydem,项目名称:yongfa365doc,代码行数:30,代码来源:UnCodeYongfa365.cs

示例6: TimeIntervalsDlg

        public TimeIntervalsDlg(Dictionary<string, DateTime> intervals)
            : this()
        {
            var nowTime = DateTime.Now;
            var maxValue = Math.Max(MaxValue, intervals.Max(i => (int) Math.Round((nowTime - i.Value).TotalDays)));

            foreach (var inter in intervals)
            {
                var ctrl = new TimeIntervalControl(inter.Key, MinValue, maxValue,
                                                   (int) Math.Round((nowTime - inter.Value).TotalDays))
                               {
                                   Height = LineHeight,
                                   Dock = DockStyle.Top
                               };
                timeControls.Add(inter.Key, ctrl);
                panelContent.Controls.Add(ctrl);
            }

            if (intervals.Count > 1)
            {
                var defaultTotal = timeControls.Values.Mode(i => i.Value);
                // контрол, масштабирующий все остальные контролы
                scaleControl = new TimeIntervalControl(Localizer.GetString("TitleAll"), MinValue, maxValue, defaultTotal)
                    {
                        Height = LineHeight,
                        Dock = DockStyle.Top,
                        fontTitle = new Font(Font, FontStyle.Bold)
                    };
                scaleControl.ValueChangedByDragging += ScaleControlOnValueChangedByDragging;
                panelContent.Controls.Add(scaleControl);
            }
        }
开发者ID:johnmensen,项目名称:TradeSharp,代码行数:32,代码来源:TimeIntervalsDlg.cs

示例7: Speak

        public Response Speak()
        {
            Dictionary<Rule, int> acceptDict = new Dictionary<Rule, int>();

            foreach (Rule rule in _ruleDb)
            {
                if (!rule.CanMatch())
                    continue;

                bool match = true;
                foreach (Criterion criterion in rule.Criteria)
                {
                    if (!_factDict.ContainsKey(criterion.Lhs) || !criterion.Compare(_factDict[criterion.Lhs] as IComparable))
                    {
                        match = false;
                        break;
                    }
                }
                if (match)
                    acceptDict.Add(rule, rule.Criteria.Count);
            }
            if (acceptDict.Count == 0)
                return new Response("NullResponse", "NO RESPONSE");

            // Of all the matched rules, find the one(s) that match the most criteria
            int maxScore = acceptDict.Max(kvp => kvp.Value);
            List<Rule> acceptList = acceptDict.Where(kvp => kvp.Value == maxScore).Select(kvp => kvp.Key).ToList();

            // Of all the matched rules of maximum criteria, return a random one
            Rule matchedRule = acceptList.RandomItem();
            matchedRule.Match();
            Response response = matchedRule.Response;
            response.Match();
            return response;
        }
开发者ID:karstendick,项目名称:DialogueLib,代码行数:35,代码来源:Query.cs

示例8: Main

 public static void Main()
 {
     Dictionary<int, int> perimeters = new Dictionary<int, int>();
     for (int i = 12; i < 1001; i += 4)
     {
         for (int j = 3; j < 334; j++)
         {
             for (int k = j; k < (i - j) / 2; k++)
             {
                 if ((i - j - k) * (i - j - k) == j * j + k * k)
                 {
                     if (perimeters.ContainsKey(i))
                     {
                         perimeters[i]++;
                     }
                     else
                     {
                         perimeters.Add(i, 1);
                     }
                 }
             }
         }
     }
     var n = perimeters.Max(p => p.Value);
     var answer = perimeters.First(q => q.Value == n).Key;
     Console.WriteLine(answer);
 }
开发者ID:ninamarkoff,项目名称:ProjectEuler,代码行数:27,代码来源:IntegerRightTriangles.cs

示例9: CalculateDesPoints

        public Dictionary<int, double> CalculateDesPoints(double alpha, double beta)
        {
            Dictionary<int, double> resultDataSet = new Dictionary<int, double>();

            double sPrev = _originalDataset[2];
            double bPrev = _originalDataset[2] - _originalDataset[1];
            resultDataSet[3] = CalculateForeCast(sPrev, bPrev);

            foreach (KeyValuePair<int, double> pair in _originalDataset.Where((x, i) => i > 1))
            {
                double sNew = CalculateS1(alpha, pair.Value, sPrev, bPrev);
                double bNew = CalculateB1(alpha, beta, sNew, sPrev, bPrev);

                resultDataSet.Add(pair.Key + 1, CalculateForeCast(sNew, bNew));

                sPrev = sNew;
                bPrev = bNew;
            }

            int iterator = 2;

            for (int i = resultDataSet.Max(m=>m.Key) + 1; i < _lines; i++)
            {
                resultDataSet.Add(i, sPrev + (iterator * bPrev));
                iterator++;
            }

            return resultDataSet;
        }
开发者ID:Denn93,项目名称:ForeCasting,代码行数:29,代码来源:DesForecasting.cs

示例10: GetMaxValue

        protected virtual int[] GetMaxValue(Dictionary<int, Card> cards)
        {
            var max = cards.Max(x => x.Value.DenoteValue);

            var indexWithMax = cards.Where(c => c.Value.DenoteValue == max)
                .Select(c => c.Key).ToArray();

            return indexWithMax;
        }
开发者ID:yzkee90,项目名称:TddKata,代码行数:9,代码来源:PokerTieBreaker.cs

示例11: Down

        public int Down(string tableName, string primaryColumn, Int64 primaryValue, string orderColumn, Int64 orderNumber)
        {
            var data = new Dictionary<string, Int64>();
            using (DataCommand cmd = DataCommandManager.GetDataCommand("CommonDown"))
            {
                cmd.CommandText = string.Format(cmd.CommandText, tableName, primaryColumn, primaryValue, orderColumn,orderNumber);
                using (IDataReader dr = cmd.ExecuteDataReader())
                {
                    while (dr.Read())
                    {
                        if (!Convert.IsDBNull(dr[primaryColumn]) && !Convert.IsDBNull(dr[orderColumn]))
                        {
                            data.Add(dr[primaryColumn].ToString(), Convert.ToInt64(dr[orderColumn]));
                        }
                    }
                }

                if (data.Count == 1)
                {
                    return 2;
                }
                else
                {
                    string sql = "update {0} set {1}={2} where {3}={4}";

                    StringBuilder sb = new StringBuilder();
                    foreach (KeyValuePair<string, long> keyValuePair in data)
                    {
                        if (keyValuePair.Key == primaryValue.ToString())
                        {
                            sb.Append(
                                string.Format(
                                    sql,
                                    tableName,
                                    orderColumn,
                                    data.Min(s => s.Value),
                                    primaryColumn,
                                    primaryValue) + ";");

                        }
                        else
                        {
                            sb.Append(
                                string.Format(
                                    sql,
                                    tableName,
                                    orderColumn,
                                    data.Max(s => s.Value),
                                    primaryColumn,
                                    keyValuePair.Key) + ";");
                        }
                    }
                    cmd.CommandText = sb.ToString();
                    return cmd.ExecuteNonQuery();
                }
            }
        }
开发者ID:jiangguang5201314,项目名称:DotNetFramework,代码行数:57,代码来源:CommonDataAccess.cs

示例12: SetChart

        public static void SetChart(Dictionary<string, int> rawValues, Chart chart)
        {
            int fmin = 0;
            int fmax = 1;

            if (rawValues.Count > 0)
            {
                fmax = rawValues.Max(x => x.Value);
                fmin = rawValues.Min(x => x.Value);
            }

            //series init
            chart.Series.Clear();
            //   chart.Tag = values;
            var s = new Series();
            s.ChartType = SeriesChartType.Bar;

            foreach (var kvp in rawValues)
            {
                s.Points.AddXY(kvp.Key, kvp.Value);
                var dpc = s.Points[s.Points.Count - 1];
                dpc.Color = ColorExtras.GetRedGreenBlendedColour(kvp.Value, 0, fmax);
                dpc.ToolTip = kvp.Key + ":" + kvp.Value;
            }

            s.YAxisType = AxisType.Primary;
            s.XAxisType = AxisType.Secondary;
            s.IsVisibleInLegend = false;
            chart.Series.Add(s);
            //chartarea init
            chart.ChartAreas.Clear();
            var ca = new ChartArea();

              //  ca.CursorX.IsUserEnabled = true;
               // ca.CursorX.IsUserSelectionEnabled = true;

            ca.AxisX2.ScrollBar.IsPositionedInside = false;
            ca.AxisX2.ScaleView.Size = zoomMax;
            ca.AxisX2.ScaleView.Position=rawValues.Count-ca.AxisX2.ScaleView.Size;

            ca.AxisX2.Interval = 1;
            ca.AxisY.Interval = MathExtras.Ceiling((Math.Abs(fmax) - Math.Abs(fmin)) / 8);
            if (ca.AxisY.Interval<1)
                ca.AxisY.Interval = 1;

            ca.AxisY.Minimum = fmin;
            ca.AxisY.Maximum = fmax;
            if (Math.Abs(ca.AxisY.Minimum - ca.AxisY.Maximum) < 1)
                ca.AxisY.Minimum--;

            s.Sort(PointSortOrder.Ascending);
            chart.ChartAreas.Add(ca);
        }
开发者ID:andreigec,项目名称:Phrase-Profiler,代码行数:53,代码来源:ChartMethods.cs

示例13: Main

        static void Main(string[] args)
        {
            string[] input = File.ReadAllLines("input.txt");

            foreach (string line in input)
            {
                Reindeers.Add(ParseReindeer(line));
            }

            Dictionary<Reindeer, int> raceDistancesStar1 = new Dictionary<Reindeer, int>();
            raceDistancesStar1 = CalculateRace(2503);

            foreach (KeyValuePair<Reindeer, int> raceDistance in raceDistancesStar1.OrderByDescending(d => d.Value))
            {
                Console.WriteLine($"Reindeer: {raceDistance.Key.Name}, Distance: {raceDistance.Value}");
            }

            Console.WriteLine($"Day 14 - Star 1, Answer: {raceDistancesStar1.OrderByDescending(rd => rd.Value).First().Key.Name} - {raceDistancesStar1.OrderByDescending(rd => rd.Value).First().Value} km");

            Dictionary<Reindeer, int> extraPoints = new Dictionary<Reindeer, int>();

            Dictionary<Reindeer, int> raceDistancesStar2 = new Dictionary<Reindeer, int>();

            for (int i = 1; i <= 2503; i++)
            {
                raceDistancesStar2 = CalculateRace(i);

                // Give current leading reindeer(s) bonus point
                IEnumerable<KeyValuePair<Reindeer, int>> leadingReindeers = raceDistancesStar2.Where(rd => rd.Value == raceDistancesStar2.Max(d => d.Value));

                foreach (KeyValuePair<Reindeer, int> leadingReindeer in leadingReindeers)
                {
                    if (!extraPoints.ContainsKey(leadingReindeer.Key))
                    {
                        extraPoints.Add(leadingReindeer.Key, 0);
                    }

                    extraPoints[leadingReindeer.Key]++;
                }
            }

            foreach (KeyValuePair<Reindeer, int> raceDistance in raceDistancesStar2.OrderByDescending(d => d.Value))
            {
                int points = 0;
                extraPoints.TryGetValue(raceDistance.Key, out points);

                Console.WriteLine($"Reindeer: {raceDistance.Key.Name}, Distance: {raceDistance.Value}, Points: {points}");
            }

            Console.WriteLine($"Day 14 - Star 2, Answer: {extraPoints.OrderByDescending(rd => rd.Value).First().Key.Name} - {extraPoints.OrderByDescending(rd => rd.Value).First().Value} points");

            Console.ReadKey();
        }
开发者ID:KoalaBear84,项目名称:AdventOfCode2015,代码行数:53,代码来源:Program.cs

示例14: Solve

        public long Solve()
        {
            var primes = new Prime(Limit);

            var numberDivisors = new Dictionary<int, int>();
            for (var number = 1; number <= Limit; number++)
            {
                var decomposition = primes.GetDecomposition(number);

                var sum = 1;
                foreach (var divisor in decomposition)
                {
                    sum *= this.GetSumDivisors(divisor);
                }
                sum -= number;

                if (sum < Limit && sum != 1)
                {
                    numberDivisors.Add(number, sum);
                }
            }

            var lines = new Dictionary<long, long>();
            foreach (var numberDivisor in numberDivisors)
            {
                var minValueStart = numberDivisor.Key;
                var nextValue = numberDivisor.Value;
                var group = new HashSet<int> { minValueStart };
                var currentCount = 1;

                while (minValueStart != nextValue && nextValue > minValueStart && currentCount == group.Count)
                {
                    if (numberDivisors.ContainsKey(nextValue))
                    {
                        group.Add(nextValue);
                        nextValue = numberDivisors[nextValue];
                        currentCount++;
                    }
                    else
                    {
                        nextValue = 0;
                    }
                }

                if (nextValue == minValueStart && group.Count > 1)
                {
                    lines.Add(minValueStart, group.Count);
                }
            }

            return lines.Where(t => t.Value == lines.Max(r => r.Value)).Min(t => t.Key);
        }
开发者ID:joeazbest,项目名称:Euler,代码行数:52,代码来源:Problem095.cs

示例15: PrintBestSequence

        static void PrintBestSequence(Dictionary<string, int> occurrences)
        {
            int bestCount = occurrences.Max(key => key.Value);
            // Match the best count with the first value it finds
            var bestEntry
                = occurrences.First(key => key.Value == bestCount).Key;

            Console.WriteLine(bestCount);
            for (int i = 0; i < bestCount; i++)
            {
                Console.WriteLine(bestEntry);
            }
        }
开发者ID:YouJinTou,项目名称:SoftUniHomework,代码行数:13,代码来源:LongestAreaInArray.cs


注:本文中的Dictionary.Max方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。