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