Preliminary algorithms - greedy B1023 set a minimum number.

 

 

#include <bits/stdc++.h>
#include<math.h>
#include <string>
using namespace std;
const int MAX_LEN = 100005;
int main(){
    int temp[10];
    for(int i =0;i<10;++i){
        temp[i] = 0;
    }
    int count = 0;
    for(int i =0;i<10;++i){
        cin>>temp[i];
        count += temp[i];
    }
    for(int i=0;i<count;++i){
        for(int j=0;j<11;++j){
            if(i == 0){
                if(temp[j+1] != 0){
                    cout<<j+1;
                    temp[j+1]--;
                    break;
                }
            }else{
                if(temp[j] != 0){
                    cout<<j;
                    temp[j]--;
                    break;
                }
            }
        }
    }
    system("pause");
    return 0;
} 

Guess you like

Origin www.cnblogs.com/JasonPeng1/p/12168891.html