QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 64 MB Total points: 20

#23752. 字符串操作

Statistics

题目描述

当给定一个仅由从 $0$ 到 $9$ 的数字构成的字符串时,考虑按照以下规则从该字符串生成新字符串的操作。从左端起按顺序每次 $1$ 个字符地读取给定的字符串,如果相同的数字 $a$ 连续出现了 $r$ 个,则按此顺序写出个数 $r$ 和数字 $a$,中间不用空格分隔。一直读取到给定字符串的右端,直至最后一次写出结束为止,即使中途进行了多次写出,整体也算作 $1$ 次操作。第 $2$ 次及之后的操作,将前一次操作写出的字符串作为给定的字符串,实施相同的操作。例如,当给定字符串 122244 时,从左端起按顺序是 $1$ 个 $1$、$3$ 个 $2$、$2$ 个 $4$,因此经过 $1$ 次该操作得到的字符串为 113224;而在 44444444444($11$ 个 $4$)的情况下,得到的字符串为 114。

请编写一个程序,输出对给定的不超过 $100$ 个字符的字符串实施 $n$ 次上述操作后得到的字符串。其中,设 $n \le 20$。

输入文件的文件名为 input.txt。input.txt 由 $2$ 行组成,第 $1$ 行写有操作次数 $n$,第 $2$ 行写有初始字符串。

输出文件的文件名为 output.txt。output.txt 为 $1$ 行,请在实施了指定次数的操作后得到的字符串之后加入换行。

样例 1

样例输入 1

5
11

样例输出 1

13112221

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.