#include<iostream>
#include<fstream>
using namespace std;
int main()
{int n,a[100],c,s,i,j;
ifstream f("date");
clock_t x,y;
x=clock();
f>>n;
for(i=1;i<=n;i++)
f>>a[i];
f>>c;
for(i=1;i<n;i++)
for(j=i+1;j<=n;j++)
if(a[i]>a[j])
swap(a[i],a[j]);
for(i=n;i>0;i--)
{s=0;
for(j=i;j>0;j--)
if(s+a[j]<=c)
{s=s+a[j];
cout<<a[j]<<" ";
a[j]=c+1;}
if(s+a[j]>=c)
cout<<endl;
}
cout<<endl;
y=clock() ;
cout<<(double)(y-x)/CLOCKS_PER_SEC;
}
Orar semigroup #2
12/12 - Proiect, Clock
luni, 12 decembrie 2011
by DlMuresan
Categories:
clock,
complexitatea algoritmilor,
proiect
|
Leave a comment