Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 02. Repeat Strings
- 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.
- Examples
- Input Output
- hi abc add hihiabcabcabcaddaddadd
- work workworkworkwork
- ball ballballballball
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace TextProcessing_Lab
- {
- class Program
- {
- static void Main(string[] args)
- {
- var arrayOfStrings = Console.ReadLine().Split();
- var concatenatedString = ""; //Simple way.
- //var concatenatedString = new StringBuilder(); //Other way.
- foreach (var word in arrayOfStrings)
- {
- for (int i = 1; i <= word.Length; i++)
- {
- concatenatedString += word;
- //concatenatedString.Append(word);
- }
- }
- Console.WriteLine($"{concatenatedString}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment