Loading...

Във форума е въведено ограничение, което позволява на потребителите единствено да разглеждат публикуваните въпроси.

FireHead avatar FireHead 44 Точки

7. * Population Counter - 30/100 - Защо?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _07_Population_Counter
{
    class Program
    {
        static void Main(string[] args)
        {
            Dictionary<string, Dictionary<string, int>> populationCounter = new Dictionary<string, Dictionary<string, int>>();

            string input = Console.ReadLine();

            while (input != "report")
            {
                string[] inputArr = input.Split('|');
                string city = inputArr[0];
                string country = inputArr[1];
                int population = int.Parse(inputArr[2]);

                if (!populationCounter.ContainsKey(country))
                {
                    populationCounter[country] = new Dictionary<string, int>();
                }

                if (!populationCounter[country].ContainsKey(city))
                {
                    populationCounter[country].Add(city, 0);
                }

                populationCounter[country][city] += population;

                input = Console.ReadLine();
            }

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

            foreach (var item in populationCounter)
            {
                mergeDict[item.Key] = item.Value.Values.Sum();
            }

            foreach (var item in mergeDict.OrderByDescending(x => x.Value))
            {
                Console.WriteLine($"{item.Key} (total population: {item.Value})");

                foreach (var index in populationCounter[item.Key].OrderByDescending(x => x.Value))
                {
                    Console.WriteLine($"=>{index.Key}: {index.Value}");
                }
            }
        }
    }
}
 

Тагове:
0
Programming Fundamentals
FireHead avatar FireHead 44 Точки

Аааа, колеги поправих се. Просто замених int с long в речниците... :) 100/100

1
FireHead avatar FireHead 44 Точки

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _07_Population_Counter
{
    class Program
    {
        static void Main(string[] args)
        {
            Dictionary<string, Dictionary<string, long>> populationCounter = new Dictionary<string, Dictionary<string, long>>();

            string input = Console.ReadLine();

            while (input != "report")
            {
                string[] inputArr = input.Split('|');
                string city = inputArr[0];
                string country = inputArr[1];
                int population = int.Parse(inputArr[2]);

                if (!populationCounter.ContainsKey(country))
                {
                    populationCounter[country] = new Dictionary<string, long>();
                }

                if (!populationCounter[country].ContainsKey(city))
                {
                    populationCounter[country].Add(city, 0);
                }

                populationCounter[country][city] += population;

                input = Console.ReadLine();
            }

            Dictionary<string, long> mergeDict = new Dictionary<string, long>();

            foreach (var item in populationCounter)
            {
                mergeDict[item.Key] = item.Value.Values.Sum();
            }

            foreach (var item in mergeDict.OrderByDescending(x => x.Value))
            {
                Console.WriteLine($"{item.Key} (total population: {item.Value})");

                foreach (var index in populationCounter[item.Key].OrderByDescending(x => x.Value))
                {
                    Console.WriteLine($"=>{index.Key}: {index.Value}");
                }
            }
        }
    }
}
 

0
Можем ли да използваме бисквитки?
Ние използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Можете да се съгласите с всички или част от тях.
Назад
Функционални
Използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Използваме „сесийни“ бисквитки, за да Ви идентифицираме временно. Те се пазят само по време на активната употреба на услугите ни. След излизане от приложението, затваряне на браузъра или мобилното устройство, данните се трият. Използваме бисквитки, за да предоставим опцията „Запомни Ме“, която Ви позволява да използвате нашите услуги без да предоставяте потребителско име и парола. Допълнително е възможно да използваме бисквитки за да съхраняваме различни малки настройки, като избор на езика, позиции на менюта и персонализирано съдържание. Използваме бисквитки и за измерване на маркетинговите ни усилия.
Рекламни
Използваме бисквитки, за да измерваме маркетинг ефективността ни, броене на посещения, както и за проследяването дали дадено електронно писмо е било отворено.