BOJ 2675 문자열 반복

1 개요[ | ]

BOJ 2675 문자열 반복
  • 문자열의 각 문자를 반복하여 출력해봅니다

2 C++[ | ]

#include <iostream>
#include <string>
using namespace std;

int main() {
    int T;
    cin >> T;
    int R, pos;
    string S;
    char out[161];
    while(T--) {
        cin >> R >> S;
        int pos = 0;
        for(int i=0; i<S.length(); i++) {
            for(int j=0; j<R; j++) {
                out[pos] = S[i];
                pos++;
            }
            out[pos] = 0;
        }
        cout << out << '\n';
    }
}

3 Java[ | ]

import java.util.*;
public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for(int i=0; i<n; i++) {
            int t = sc.nextInt();            
            String str = sc.next();
            for(int j=0; j<str.length(); j++) {
                for(int k=0; k<t; k++)
                    System.out.print(str.charAt(j));
            }
            System.out.print("\n");
        }
    }
}

4 Perl[ | ]

$n = <>;
for (1..$n) {
    ($m, $o) = split / +/, <>;
    chomp $o;
    printf("%s", $_ x $m) for (split //, $o);
    printf("\n");
}

5 PHP[ | ]

<?php
$T = intval(fgets(STDIN));
for($i=0; $i<$T; $i++) {
    list($R, $S) = explode(' ',rtrim(fgets(STDIN)));
    for($j=0; $j<strlen($S); $j++) {
        echo str_repeat($S[$j],$R);
    }
    echo "\n";
}

6 Python[ | ]

TT = int(input())
for t in range(TT):
    R, S = input().split()
    for ch in S:
        print( ch*int(R), end='')
    print()
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}