题目链接
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/
欢迎讨论和交流!