PhieuLang

Distribute

Apr 23rd, 2012
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. void out_array(int a[],int n)
  5. {
  6.     for(int i=0;i<n;i++)
  7.         cout<<a[i]<<" ";
  8. }
  9. void Distribute(int a[],int n,int b[],int &nb,int c[],int &nc,int k)
  10. {
  11.     int i,pa,pb,pc;
  12.     pa=pb=pc=0;
  13.     while(pa<n);
  14.     {
  15.         cout<<pa<<" and "<<n<<endl;
  16.         for(i=0;(pa<n)&&(i<k);i++,pa++,pb++)
  17.             b[pb]=a[pa];
  18.         for(i=0;(pa<n)&&(i<k);i++,pa++,pc++)
  19.             c[pc]=a[pa];
  20.     }
  21.     nb=pb; nc=pc;
  22. }
  23. int main()
  24. {
  25.     int n=8,a[8]={12,2,8,5,1,6,4,15};
  26.     int b[n],c[n],nb,nc;
  27.     Distribute(a,n,b,nb,c,nc,1);
  28.     out_array(b,nb);
  29.     cout<<endl<<"===="<<endl;
  30.     out_array(c,nc);
  31.     cout<<endl;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment