CF2204E.Sum of Digits (and Again)
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
For a positive (strictly greater than 0) integer x, the string S(x) is formed through the following process:
- initially, this string is empty;
- then, the decimal representation of the number x without leading zeros is appended to it on the right;
- after that, if x≤9, the process ends. Otherwise, x is replaced by the sum of the digits of x, and the process returns to step 2;
For example:
- S(75) is 75123;
- S(30) is 303;
- S(9) is 9.
You are given a string s consisting of digits. Your task is to rearrange the characters in this string so that it forms the string S(x) for some number x. Removing characters and/or adding new characters is not allowed. If the given string s is already the string S(x) for some number x, you may leave it unchanged.
对于一个正整数 x(严格大于 0),字符串 S(x) 通过以下过程生成:
- 初始时,该字符串为空;
- 然后,将 x 的十进制表示(不含前导零)追加到该字符串的右侧;
- 接着,若 x≤9,则过程结束;否则,将 x 替换为其各位数字之和,并返回第 2 步;
例如:
- S(75) 是
75123; - S(30) 是
303; - S(9) 是
9。
给定一个仅由数字组成的字符串 s。你的任务是重新排列该字符串中的字符,使其构成某个数 x 对应的字符串 S(x)。不允许删除或添加任何字符。如果给定的字符串 s 已经是某个数 x 对应的 S(x),你可以保持其不变。
输入格式
The first line contains one integer t (1≤t≤104) — the number of test cases.
Each test case consists of one string containing s (1≤∣s∣≤105) — a sequence of digits.
Additional constraints on the input:
- the sum of lengths of s over all test cases does not exceed 105;
- it is possible to rearrange the digits in s to obtain S(x) for some positive integer x.
第一行包含一个整数 t(1≤t≤104)—— 测试用例的数量。
每个测试用例由一个字符串 s(1≤∣s∣≤105)组成 —— 一串数字。
输入的额外约束条件:
- 所有测试用例中字符串 s 的长度总和不超过 105;
- 字符串 s 中的数字可以被重新排列,从而得到某个正整数 x 对应的 S(x)。
输出格式
For each test case, output one string — s after rearranging the characters. If there are multiple valid answers, output any of them.
对于每个测试用例,输出一个字符串——即重排字符后的 s。如果存在多个合法的答案,输出其中任意一个即可。
输入输出样例
输入#1
5 12735 1 011 99999299999999299959999999999999 4621467
输出#1
75123 1 101 99999999999999999999999999992529 6442167
输入解题思路,AI测评打分。不知道怎么写?