Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream.h>
- int fact(int);
- int main()
- {
- int t[10];
- int b[10];
- int c[10];
- int d[10];
- int e[10];
- int m[10];
- int k[10];
- int l[10];
- int a,comb,i,j,p,q,v=0,temp;
- cout<<"Enter the number of tapes:\n";
- cin>>a;
- comb=fact(a);
- cout<<"enter the time of the tapes:\n";
- for(i=0;i<a;i++)
- {
- cout<<"time of tape 1: ";
- cin>>t[i];
- }
- for(i=1;i<=a;i++)
- {
- for(j=1;j<=2;j++)
- {
- q=a-((a-i)-j);
- p=a-((a-i)-(j+1));
- if(q>a)
- q=(q-a);
- if(p>a)
- p=(p-a);
- b[v]=t[i-1];
- c[v]=t[q-1];
- d[v]=t[p-1];
- m[v]=i;
- k[v]=q;
- l[v]=p;
- v++;
- cout<<m[v-1]<<k[v-1]<<l[v-1]<<" "<<b[v-1]<<" "<<c[v-1]<<" "<<d[v-1]<<endl;
- }
- }
- for(i=0;i<comb;i++)
- e[i]=b[i]+b[i]+c[i]+b[i]+c[i]+d[i];
- temp=0;
- for(i=0;i<comb;i++)
- {
- if(e[i]<e[temp])
- temp=i;
- }
- cout<<"the optimal storage order is: "<<m[temp]<<k[temp]<<l[temp]<<"\n";
- cout<<"time used is "<<e[temp]<<endl;
- return 0;
- }
- int fact(int x)
- {
- int facto=1;
- if(x==1||x==0)
- return 1;
- else
- {
- return x*fact(x-1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment