fork download
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5.  
  6. int main(){
  7.  
  8. int a[5]={0,0,0,0,0};
  9. int b[5]={0,2,1,2,6};//上限值
  10.  
  11. int tmp;
  12.  
  13. int i,j;
  14.  
  15. for(i=0;i<10;i++)
  16. {
  17. tmp=rand()%5;
  18. if( a[tmp] < b[tmp] )
  19. a[tmp]++;
  20. else
  21. i--;
  22. }
  23.  
  24. for( j=0 ; j<5 ; ++j )
  25. cout << a[j] << "\t";
  26. cout << endl;
  27.  
  28. return 0;
  29. }
  30.  
Success #stdin #stdout 0.02s 2724KB
stdin
Standard input is empty
stdout
0	2	1	2	5