1006
/*
讓我們用字母 B 來表示“百”建炫、字母 S 表示“十”酌儒,用 12...n 來表示不為零的個位數(shù)字 n(<10)阅羹,換個格式來輸出任一個不超過 3 位的正整數(shù)间校。例如 234 應(yīng)該被輸出為 BBSSS1234矾克,因為它有 2 個“百”、3 個“十”撇簿、以及個位的 4聂渊。
輸入格式:
每個測試輸入包含 1 個測試用例,給出正整數(shù) n(<1000)四瘫。
輸出格式:
每個測試用例的輸出占一行汉嗽,用規(guī)定的格式輸出 n。
輸入樣例 1:
234
輸出樣例 1:
BBSSS1234
輸入樣例 2:
23
輸出樣例 2:
SS123
*/
/*我的辣雞代碼
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int result;
cin>>result;
for(int i = 0;i<result/100;i++){
cout<<"B";
}
for(int i = 0;i<(result%100)/10;i++){
cout<<"S";
}
for(int i = 1;i<=(result%10);i++){
cout<<i;
}
return 0;
}
*/
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
string n;
cin >> n;
int s = n.size(); // s為字符串長度
for (int i = 0; i < s; ++i) {
// j不僅負責(zé)計數(shù)找蜜,還負責(zé)遍歷從'1'到n[i]之間的字符
for (char j = '1'; j <= n[i]; ++j) {
// i為j-3說明是百位饼暑,i為j-2說明是十位,否則是個位
cout << (i == s - 3 ? 'B' : i == s - 2 ? 'S' : j);
}
}
return 0;
}
1009
/*
給定一句英語洗做,要求你編寫程序弓叛,將句中所有單詞的順序顛倒輸出。
輸入格式:
測試輸入包含一個測試用例诚纸,在一行內(nèi)給出總長度不超過 80 的字符串撰筷。字符串由若干單詞和若干空格組成,其中單詞是由英文字母(大小寫有區(qū)分)組成的字符串畦徘,單詞之間用 1 個空格分開毕籽,輸入保證句子末尾沒有多余的空格。
輸出格式:
每個測試用例的輸出占一行井辆,輸出倒序后的句子关筒。
輸入樣例:
Hello World Here I Come
輸出樣例:
Come I Here World Hello
*/
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
string s;
stack<string> st;
//以空格為間隔符將每個字符串入棧
while (cin >> s) {
st.push(s);
if(cin.get()=='\n') break;//僅是為了使自己回車后可以運行結(jié)果
}
//empty函數(shù)返回一個bool值,棧為空時返回true杯缺,否則返回false
while (!st.empty()) {
cout << st.top();//top函數(shù)的返回值是棧頂元素(注意并沒有刪掉棧頂元素)
st.pop();//pop函數(shù)將棧頂元素刪掉蒸播,沒有返回值
cout << (st.empty() ? "" : " ");
}
return 0;
}
參考鏈接:
https://www.cnblogs.com/magisk/p/9193351.html
https://blog.csdn.net/aaakkk_1996/article/details/88040627?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase