Advertisement
gospod1978

List-Ex/More/Messaging

Oct 23rd, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.50 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace fundamental14
  6. {
  7.     class MainClass
  8.     {
  9.         public static void Main()
  10.         {
  11.             List<string> numbers = Console.ReadLine().Split().ToList();
  12.  
  13.             string text = Console.ReadLine();
  14.  
  15.             List<char> duma = new List<char>();
  16.  
  17.             List<string> final = new List<string>();
  18.  
  19.             List<int> index = new List<int>();
  20.  
  21.             for (int i = 0; i < text.Length; i++)
  22.             {
  23.                 duma.Add(text[i]);
  24.             }
  25.  
  26.             int sum = 0;
  27.  
  28.             for (int i = 0; i < numbers.Count; i++)
  29.             {
  30.                 string amount = numbers[i];
  31.                
  32.                 for (int z = 0; z < amount.Length; z++)
  33.                 {
  34.                     int chislo = int.Parse(amount[z].ToString());
  35.  
  36.                     sum += chislo;
  37.                 }
  38.                
  39.                 if (duma.Count < sum)
  40.                 {
  41.                     sum = sum - duma.Count;
  42.                 }
  43.  
  44.                 index.Add(sum);
  45.  
  46.                 sum = 0;
  47.             }
  48.  
  49.             for (int j = 0; j < index.Count; j++)
  50.             {
  51.                 int removeIndex = index[j];
  52.  
  53.                 final.Add(duma[removeIndex].ToString());
  54.                 duma.RemoveAt(removeIndex);
  55.             }
  56.  
  57.             for (int k = 0; k < final.Count; k++)
  58.             {
  59.                 Console.Write(final[k]);
  60.             }
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement