Advertisement
Guest User

Untitled

a guest
Dec 17th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp2
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<int> list = new List<int>();
  14.             Console.WriteLine("Введите массив: ");
  15.             foreach (var el in Console.ReadLine().Split(' '))
  16.                 list.Add(int.Parse(el));
  17.             Console.WriteLine("Введите элемент: ");
  18.             int elem = int.Parse(Console.ReadLine());
  19.             for (int i = 0; i < list.Count; ++i)
  20.             {
  21.                 if(elem < list[i])
  22.                 {
  23.                     list.Insert(i, elem);
  24.                     break;
  25.                 }
  26.             }
  27.  
  28.             int index = 0;
  29.             int summ = -1;
  30.             for(int i = 0; i < list.Count; ++i)
  31.             {
  32.                 int temp = 0;
  33.                 var str = list[i].ToString().ToCharArray();
  34.                 for (int j = 0; j < str.Length; ++j)
  35.                     temp += (int)(str[j] - '0');
  36.                 if (temp < summ || summ == -1)
  37.                 {
  38.                     summ = temp;
  39.                     index = i;
  40.                 }
  41.             }
  42.             list.RemoveAt(index);
  43.  
  44.             foreach (int i in list)
  45.                 Console.Write(i + " ");
  46.             Console.WriteLine();
  47.             Console.ReadKey();
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement