//只有90分,实在找不出哪里错了或者什么情况忽略了
#include<iostream>
#include<string>
using namespace std;
int main(){
	int a[20][5],n,i,j,k,count = 1,ok = 1;
	for(i=0;i<20;i++)
	 for(j=0;j<5;j++)
	   a[i][j] = count++;
	cin>>n;
	int p[n];
	for(i=0;i<n;i++) cin>>p[i];
	for(i=0;i<n;i++){
		
		for(j=0;j<20;j++){
			count = 0;
			for(k=0;k<5;k++){
				if(a[j][k]>0) count++; 
			   }
			   	if(count>=p[i]) {
			   	while(p[i]){
			   		cout<<a[j][k-count];
			   		a[j][k-count] = 0;
			   		count--;
			   		p[i]--;
			   		if(p[i]) cout<<" "; 
				   }
				   ok = 1;
				break;   
			   }
			   else ok=0;
			}
			if(i<n-1&&ok==1) cout<<"\n";
			else if(ok||i>=n-1) break; 
		}
	}
原文:http://www.cnblogs.com/whitehouse2016/p/6568116.html