Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace GroupNumbers
- {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- public class Startup
- {
- private static Dictionary<int, HashSet<int>> matrixImitation;
- private static int currentIndex;
- public static void Main()
- {
- matrixImitation = new Dictionary<int, HashSet<int>>
- {
- [0] = new HashSet<int>(),
- [1] = new HashSet<int>(),
- [2] = new HashSet<int>()
- };
- currentIndex = 0;
- int[] allElements = Console.ReadLine()
- .Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)
- .Select(ParseStringsAndPlaceThemWhereNeeded)
- .ToArray();
- StringBuilder result = new StringBuilder();
- foreach (KeyValuePair<int, HashSet<int>> kvp in matrixImitation)
- {
- foreach (int indexOfElement in kvp.Value)
- {
- result.Append(allElements[indexOfElement]);
- result.Append(" ");
- }
- result.AppendLine();
- }
- Console.Write(result);
- }
- private static int ParseStringsAndPlaceThemWhereNeeded(string toParse)
- {
- int number = int.Parse(toParse);
- int remainder = Math.Abs(number) % 3;
- matrixImitation[remainder].Add(currentIndex);
- currentIndex++;
- return number;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement