B1023 set a minimum number (20 minutes)

First, the technical summary

  1. The main question of the treatment point is not output digital 0 in the first place, offers two solution ideas here.
    • Is a direct directly in a for loop determines a position as long as the output, whether the number 0 may be output.
    • There is a direct output for a loop after a break. The end of the cycle, then you can start from 0 to traverse all digital output directly.

Second, the reference code (which is the first Solutions)

#include<iostream>
using namespace std;
int hashTable[11];
int main(){
    int num;//记录每个数字的个数 
    for(int i = 0; i < 10; i++){
        cin >> num;
        hashTable[i] = num; 
    }
    for(int i = 0; i < 10; i++){
        if(hashTable[i] > 0 && i != 0){
            while(hashTable[i] > 0){
                cout << i;
                hashTable[i]--;
                if(hashTable[0] > 0){
                    while(hashTable[0] > 0){
                        cout << 0;
                        hashTable[0]--;
                    }
                }
            }

        }
    }
    return 0;
}

Guess you like

Origin www.cnblogs.com/tsruixi/p/11824828.html