[C#] 백준 2675번 문자열 반복

2021. 12. 19. 00:50코딩테스트 문제 풀이/[백준] 문자열

728x90
반응형

using System;
using System.Collections.Generic;
namespace _4
{
    class Program
    {
        static void Main(string[] args)
        {
            int T = Convert.ToInt32(Console.ReadLine());

            for (int l = 0; l < T; l++)
            {
                string input = Console.ReadLine();
                string[] tmp = new string[2];
                tmp = input.Split(" ");
                int R = Convert.ToInt32(tmp[0]);
                string S = tmp[1];

                List<string> array = new();

                
                for (int i = 0; i < S.Length; i++)
                {
                    for (int j = 0; j < R; j++)
                    {
                        array.Add(Convert.ToString(S[i]));
                    }
                }
                foreach (var item in array)
                {
                    Console.Write(item);
                }
                Console.WriteLine();
            }
        }

    }
}

2중포문을 통해 알파벳하나씩 뽑아낸다음에 반복하고 싶은 횟수만큼 반복시켜서 배열로 만든다음 배열을 출력하면 된다.

728x90
반응형