Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Main()
- {
- List<string> inList = Console.ReadLine()
- .Split(' ').ToList();
- List<string> wordList = new List<string>();
- List<int> countList = new List<int>();
- for (int i = 0; i < inList.Count; i++)
- {
- if (!wordList.Contains(inList[i]))
- {
- wordList.Add(inList[i]);
- countList.Add(1);
- }
- else
- {
- for (int j = 0; j < wordList.Count; j++)
- {
- if (wordList[j].Equals(inList[i]))
- {
- countList[j]++;
- }
- }
- }
- }
- BubleSort(wordList, countList);
- int sum = 0;
- for (int i = 0; i < countList.Count; i++)
- {
- sum += countList[i];
- }
- for (int i = 0; i < wordList.Count; i++)
- {
- double percentage = countList[i] / (double)sum * 100;
- Console.WriteLine($"{wordList[i]} -> {countList[i]} times ({percentage:f2}%)");
- }
- }
- private static void BubleSort(List<string> list1, List<int> list2)
- {
- bool isSorted = true;
- do
- {
- isSorted = true;
- for (int i = 0; i < list1.Count - 1; i++)
- {
- if (list2[i] < list2[i + 1])
- {
- string temp1 = list1[i];
- list1[i] = list1[i + 1];
- list1[i + 1] = temp1;
- int temp2 = list2[i];
- list2[i] = list2[i + 1];
- list2[i + 1] = temp2;
- isSorted = false;
- }
- }
- } while (!isSorted);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement