JulianJulianov

02.TextProcessingLab-Repeat Strings

Apr 13th, 2020
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 KB | None | 0 0
  1. 02. Repeat Strings
  2. Write a program that reads an array of strings. Each string is repeated N times, where N is the length of the string. Print the concatenated string.
  3. Examples
  4. Input                                Output
  5. hi abc add                           hihiabcabcabcaddaddadd
  6. work                                 workworkworkwork
  7. ball                                 ballballballball
  8.  
  9.  
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Text;
  14.  
  15. namespace TextProcessing_Lab
  16. {
  17.     class Program
  18.     {
  19.         static void Main(string[] args)
  20.         {
  21.             var arrayOfStrings = Console.ReadLine().Split();
  22.             var concatenatedString = "";                       //Simple way.
  23.             //var concatenatedString = new StringBuilder();    //Other way.
  24.             foreach (var word in arrayOfStrings)
  25.             {
  26.                 for (int i = 1; i <= word.Length; i++)
  27.                 {
  28.                     concatenatedString += word;
  29.                     //concatenatedString.Append(word);
  30.                 }
  31.             }
  32.             Console.WriteLine($"{concatenatedString}");
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment