Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Lists
- {
- class Program
- {
- static int DigitSum(int number)
- {
- int sum = 0;
- while (number != 0)
- {
- sum += number % 10;
- number /= 10;
- }
- return sum;
- }
- static void Main(string[] args)
- {
- int[] numbers = Console.ReadLine()
- .Split(',')
- .Select(n => int.Parse(n))
- .ToArray();
- List<int> gr1 = new List<int>();
- List<int> gr2 = new List<int>();
- List<int> gr3 = new List<int>();
- List<int> gr4 = new List<int>();
- foreach (var item in numbers)
- {
- if (item % 10 == 4 || item % 10 == 2)
- {
- gr1.Add(item);
- }
- else if (item % 10 == 5 || item % 10 == 7)
- {
- gr2.Add(item);
- }
- if (DigitSum(item) % 10 == 3)
- {
- gr3.Add(item);
- }
- else if (DigitSum(item) % 10 == 6)
- {
- gr4.Add(item);
- }
- }
- Console.WriteLine(string.Join(",", gr1));
- Console.WriteLine(string.Join(",", gr2));
- Console.WriteLine(string.Join(",", gr3));
- Console.WriteLine(string.Join(",", gr4));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement