題目地址:https://pintia.cn/problem-sets/994805260223102976/problems/994805318855278592ios
讓咱們用字母 B
來表示「百」、字母 S
表示「十」,用 12...n
來表示不爲零的個位數字 n
(<10),換個格式來輸出任一個不超過 3 位的正整數。例如 234
應該被輸出爲 BBSSS1234
,由於它有 2 個「百」、3 個「十」、以及個位的 4。測試
每一個測試輸入包含 1 個測試用例,給出正整數 n(<1000)。spa
每一個測試用例的輸出佔一行,用規定的格式輸出 n。code
234
BBSSS1234
23
SS123
對不超過3位的正整數進行拆分,找出其百位,十位,各位格式多少,對應輸出便可。可貴的一次AC。ci
#include<iostream> using namespace std; int main() { int number = 0; cin >> number; // 百位 int x = number / 100; number %= 100; // 十位 int y = number / 10; // 個位 number %= 10; for (int i = 0; i < x; i++) { cout << "B"; } for (int i = 0; i < y; i++) { cout << "S"; } for (int i = 0; i < number; i++) { cout << i + 1; } return 0; }