PTA 1006 换个格式输出整数

作者: freesan44 | 来源:发表于2021-08-15 06:11 被阅读0次

题目

让我们用字母 B 来表示“百”、字母 S 表示“十”,用 12...n 来表示不为零的个位数字 n(<10),换个格式来输出任一个不超过 3 位的正整数。例如 234 应该被输出为 BBSSS1234,因为它有 2 个“百”、3 个“十”、以及个位的 4。

输入格式:
每个测试输入包含 1 个测试用例,给出正整数 n(<1000)。

输出格式:
每个测试用例的输出占一行,用规定的格式输出 n。

输入样例 1:
234
结尾无空行
输出样例 1:
BBSSS1234
结尾无空行
输入样例 2:
23
结尾无空行
输出样例 2:
SS123
结尾无空行

解题思路

count = int(input())
# count = 234
outPutStr = ""
# 处理百位
baiweiCount = count//100
for i in range (baiweiCount):
    outPutStr = outPutStr + "B"
# 处理十位
shiweiCount = (count % 100)//10
for j in range(shiweiCount):
    outPutStr = outPutStr + "S"
# 处理个位
geweiCount = count%10
for k in range(1,geweiCount+1):
    outPutStr = outPutStr + str(k)
print(outPutStr)

相关文章

网友评论

    本文标题:PTA 1006 换个格式输出整数

    本文链接:https://www.haomeiwen.com/subject/czkebltx.html