yanass

Messaging

Jun 19th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.68 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Messaging
  6. {
  7.     class Program
  8.     {
  9.         static void Main()
  10.         {
  11.             List<int> numbers = Console.ReadLine()
  12.                 .Split()
  13.                 .Select(int.Parse)
  14.                 .ToList();
  15.  
  16.             string text = Console.ReadLine();
  17.             List<char> textSplit = text.ToList();
  18.  
  19.             List<char> textToPrint = new List<char>();
  20.             SumNumbersInList(numbers);
  21.            
  22.             for (int i = 0; i < numbers.Count; i++)
  23.             {
  24.                 int indexToRemove = IndexToRemove(textSplit.Count, numbers[i]);
  25.                 textToPrint.Add(textSplit[indexToRemove]);
  26.                 textSplit.RemoveAt(indexToRemove);
  27.                 //count++;
  28.             }
  29.  
  30.  
  31.             Console.WriteLine(string.Join("", textToPrint));
  32.  
  33.         }
  34.  
  35.         static void SumNumbersInList(List<int> numbers)
  36.         {
  37.  
  38.             for (int i = 0; i < numbers.Count; i++)
  39.             {
  40.                 int sumDigits = 0;
  41.                 while (numbers[i] != 0)
  42.                 {
  43.                     sumDigits += numbers[i] % 10;
  44.                     numbers[i] /= 10;
  45.                 }
  46.  
  47.                 numbers[i] = sumDigits;
  48.  
  49.             }
  50.         }
  51.  
  52.         static int IndexToRemove(int textLength, int index)
  53.         {
  54.             if (textLength > index)
  55.                 return index;
  56.  
  57.             else if (textLength == index)
  58.                 return 0;
  59.  
  60.             else
  61.             {
  62.                 int timesInIndex = index / textLength;
  63.  
  64.                 return index - (timesInIndex * textLength);
  65.             }
  66.         }
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment