PAT乙级1023
題目鏈接
https://pintia.cn/problem-sets/994805260223102976/problems/994805298269634560
題解
主要就是控制首位不能為0,其他的都很簡單,就遍歷然后往尾部加數字就好了。
// PAT BasicLevel 1023 // https://pintia.cn/problem-sets/994805260223102976/problems/994805298269634560#include <iostream> using namespace std;int main() {// 結果string res="";// 獲取數字零的數量int zeroCount;cin >>zeroCount;// 標志是否為第一個數量超過0個的數字bool isFirst=true;// 非零數字個數int count;// 獲取非零數字的數量并生成最終結果for(char c='1';c<='9';++c){// 獲取非零數數量cin >> count;// 該數字的數量超過0個時if(count>0){// 如果是第一個數量超過0的非零數字if (isFirst){// 先把它加在最前邊,因為首位不可以是0res+=c;count--;// 把零加在前邊for(int i=0;i<zeroCount;++i){res+='0';}// 更新標志isFirst=false;}// 加自己for (int i = 0; i < count; ++i){res += c;}}}// 輸出形成的最小數cout << res;//system("pause");return 0; }作者:@臭咸魚
轉載請注明出處:https://www.cnblogs.com/chouxianyu/
歡迎討論和交流!
轉載于:https://www.cnblogs.com/chouxianyu/p/11309268.html
總結
- 上一篇: 【搜索】$P1092$虫食算
- 下一篇: 将Array、Dictionary等集合