代碼
#include <iostream>
#include <sstream>
using namespace std;
const int MAX = 10;
string intToString(int t){
stringstream ss;
ss<<t;
string tmp;
ss>>tmp;
return tmp;
}
int main(){
int digit[MAX] = {0};
for(int i=0; i<MAX; i++){
cin>>digit[i];
}
string ans;
//find first number
for(int i=1; i<MAX; i++){
if(digit[i]>0){
ans = ans + intToString(i);
digit[i]--;
break;
}
}
//find other number
for(int i=0; i<MAX; i++){
while(digit[i]>0){
ans = ans + intToString(i);
digit[i]--;
}
}
cout<<ans<<endl;
return 0;
}
注解
1、利用stringstream,整型轉String
#include <sstream>
string intToString(int t){
stringstream ss;
ss<<t;
string tmp;
ss>>tmp;
return tmp;
}