upsidedown

not perfect daa

Mar 1st, 2012
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #include<iostream.h>
  2.  
  3. int fact(int);
  4.  
  5. int main()
  6. {
  7.     int t[10];
  8.     int b[10];
  9.     int c[10];
  10.     int d[10];
  11.     int e[10];
  12.     int m[10];
  13.     int k[10];
  14.     int l[10];
  15.     int a,comb,i,j,p,q,v=0,temp;
  16.     cout<<"Enter the number of tapes:\n";
  17.     cin>>a;
  18.     comb=fact(a);
  19.     cout<<"enter the time of the tapes:\n";
  20.     for(i=0;i<a;i++)
  21.     {
  22.         cout<<"time of tape 1: ";
  23.         cin>>t[i];
  24.     }
  25.     for(i=1;i<=a;i++)
  26.     {
  27.         for(j=1;j<=2;j++)
  28.         {
  29.             q=a-((a-i)-j);
  30.             p=a-((a-i)-(j+1));
  31.             if(q>a)
  32.                 q=(q-a);
  33.             if(p>a)
  34.                 p=(p-a);
  35.             b[v]=t[i-1];
  36.             c[v]=t[q-1];
  37.             d[v]=t[p-1];
  38.             m[v]=i;
  39.             k[v]=q;
  40.             l[v]=p;
  41.             v++;
  42.             cout<<m[v-1]<<k[v-1]<<l[v-1]<<"  "<<b[v-1]<<" "<<c[v-1]<<" "<<d[v-1]<<endl;
  43.         }
  44.  
  45.     }
  46.     for(i=0;i<comb;i++)
  47.         e[i]=b[i]+b[i]+c[i]+b[i]+c[i]+d[i];
  48.     temp=0;
  49.     for(i=0;i<comb;i++)
  50.     {
  51.         if(e[i]<e[temp])
  52.             temp=i;
  53.     }
  54.     cout<<"the optimal storage order is: "<<m[temp]<<k[temp]<<l[temp]<<"\n";
  55.     cout<<"time used is "<<e[temp]<<endl;
  56.     return 0;
  57. }
  58.  
  59. int fact(int x)
  60. {
  61.     int facto=1;
  62.     if(x==1||x==0)
  63.         return 1;
  64.     else
  65.     {
  66.        
  67.         return x*fact(x-1);
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment