Log inSign up
Problems / B020

Stretching a pattern sideways

100 ptsCases 15Set by dongbinna
Added October 30.
1 solved1 attempted1 submissionssolvers took 1.0 tries on average

Statement

A workshop writes its knitting patterns down as text. A pattern is a single-line string, and one symbol in the string stands for one cell of the pattern. A different symbol means a different color of yarn knitted in that cell.

When the workshop wants to knit the same motif wider, it stretches the pattern sideways. To stretch a pattern sideways by a factor of R, each symbol of the pattern is written R times in a row, going from the left. For example, if the pattern is ABC and the factor is 3, writing A three times, then B three times, then C three times gives AAABBBCCC. The length of the stretched pattern is the length of the original pattern times the factor. When the factor is 1, the pattern stays as it is.

The workshop has several patterns to stretch, and the factor differs from pattern to pattern. The patterns are written one per line, and each line holds the factor for that pattern and the pattern itself, split by one space. Before the space is the factor, and after the space is the pattern. A pattern itself holds no space, so a line always holds exactly one space.

Given T patterns in total and the factor for each pattern, write a program that prints the stretched patterns in order.

For example, suppose T=2 patterns are given, and the factor and the content of each pattern are as in the table below.

Pattern numberFactorPatternLength of the pattern
13ABC3
25/HTP4

Pattern 1 has the three symbols A, B, and C and a factor of 3, so each symbol is written three times in a row. Pattern 2 has the four symbols /, H, T, and P and a factor of 5, so each symbol is written five times in a row. The results are the following.

Pattern numberStretched patternLength of the stretched pattern
1AAABBBCCC9
2/////HHHHHTTTTTPPPPP20

As in pattern 2, a symbol that is not an English letter is stretched in just the same way, with no exception. When the same symbol appears several times in a pattern, each place it appears is stretched R times on its own.

Input and Output Examples

Example 1

Input

2
3 ABC
5 /HTP

Output

AAABBBCCC
/////HHHHHTTTTTPPPPP

Example 2

Input

2
4 N3CJRWPB5
1 02X

Output

NNNN3333CCCCJJJJRRRRWWWWPPPPBBBB5555
02X

Example 3

Input

1
2 C8eAVXXQPKJ

Output

CC88eeAAVVXXXXQQPPKKJJ

Input

  • First, the number of patterns T is given on the first line. T is a natural number between 1 and 20.

  • Next, over T lines, the information for each pattern is given in order of pattern number. Each line first gives the factor R, then one space, then the pattern string S. R is a natural number between 1 and 8. S is made of uppercase and lowercase English letters, digits, and symbols, and it holds no space. The length of S is between 1 and 20.

Output

  • Print T lines. The i-th line holds the i-th pattern stretched sideways by a factor of R. Put no space between the symbols, and leave no space at the end of a line either. Do not attach a blank line after the last of the T lines.

Requirements

  • Read the input from standard input and write the answer to standard output
  • The first number on each line is the factor, and what comes after the space is the pattern
  • A pattern can mix in symbols as well as uppercase and lowercase English letters and digits. You have to stretch every character the same way, whatever kind it is
  • Print one stretched pattern per line. Putting a space between the symbols gives a wrong answer
  • Grading compares the output with the expected value down to the last character
  • You must write a program that reads from standard input and writes to standard output
  • Trailing spaces at the end of a line and blank lines at the end of the output are ignored when grading
  • The languages you can use are Python and JavaScript
  • The memory limit is 256MB. The browser does not measure it, it only states it
  • The time limit is set by measuring the setter's reference solution on the same runtime
  • On this problem you submit code, not a prompt. That code runs in the browser on this device, and all that goes to the server is a fingerprint of the output and the time it took. Whether it is correct is decided by the server. The run time is a number each device reports, so the code and the device details are posted next to it on the leaderboard.
  • There are 15 cases, and 3 of them show the input together with the expected output. The rest are used only when you submit and are not shown on this page.
  • You have to pass all 15 cases to solve this.
Read the requirements carefully before solving. Tampering with the grading to make a submission look like a pass can get you sanctioned if caught. The code you submit is published on the leaderboard along with the result.

Examples

3 public cases. Judging also uses hidden cases. You have to pass all 15 cases to solve this.

Input
Expected output
2
3 ABC
5 /HTP
AAABBBCCC
/////HHHHHTTTTTPPPPP
1
2 C8eAVXXQPKJ
CC88eeAAVVXXXXQQPPKKJJ
2
4 N3CJRWPB5
1 02X
NNNN3333CCCCJJJJRRRRWWWWPPPPBBBB5555
02X

Solution

Your code runs on this device. Only the fingerprint of the output and the elapsed time go to the server. The server decides whether it is correct.

0 chars1 lineMemory 256MB (recorded only)Reference 2.0ms

Submitting requires you to log in. Running against the public cases works without one.

You can test with 3 public cases. Submitting runs the hidden cases too.

People who solved this problem

The time shown is the time spent solving. Input reading time is outside the solver's control, so it is excluded. And since each device reports this value itself, we record which device measured it.

1bampal259ms402 charsPythonLinux / Chrome/158.0.8127.18 / 2코어 / 16GB

Log in and you can see the code once you solve this problem.