Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp2
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<int> list = new List<int>();
- Console.WriteLine("Введите массив: ");
- foreach (var el in Console.ReadLine().Split(' '))
- list.Add(int.Parse(el));
- Console.WriteLine("Введите элемент: ");
- int elem = int.Parse(Console.ReadLine());
- for (int i = 0; i < list.Count; ++i)
- {
- if(elem < list[i])
- {
- list.Insert(i, elem);
- break;
- }
- }
- int index = 0;
- int summ = -1;
- for(int i = 0; i < list.Count; ++i)
- {
- int temp = 0;
- var str = list[i].ToString().ToCharArray();
- for (int j = 0; j < str.Length; ++j)
- temp += (int)(str[j] - '0');
- if (temp < summ || summ == -1)
- {
- summ = temp;
- index = i;
- }
- }
- list.RemoveAt(index);
- foreach (int i in list)
- Console.Write(i + " ");
- Console.WriteLine();
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement