1006 換個格式輸出整數 (15分)
題目地址:https://pintia.cn/problem-sets/994805260223102976/problems/994805318855278592
讓我們用字母 B 來表示“百”、字母 S 表示“十”,用 12...n 來表示不為零的個位數字 n(<10),換個格式來輸出任一個不超過 3 位的正整數,例如 234 應該被輸出為 BBSSS1234,因為它有 2 個“百”、3 個“十”、以及個位的 4,
輸入格式:
每個測驗輸入包含 1 個測驗用例,給出正整數 n(<1000),
輸出格式:
每個測驗用例的輸出占一行,用規定的格式輸出 n,
輸入樣例1
234
輸出樣例1
BBSSS1234
輸入樣例2
23
輸出樣例2
SS123
我的理解
對不超過3位的正整數進行拆分,找出其百位,十位,各位格式多少,對應輸出即可,難得的一次AC,
代碼段
#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;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/110924.html
標籤:其他
上一篇:紅黑樹——自平衡程序
下一篇:PAT乙級1007
