Advertisement
Guest User

Untitled

a guest
May 28th, 2015
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.45 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. void Print(int * A, int l)
  5. {
  6.      bool dig=false;
  7.      for(int i=1;i<=l;i++) {
  8.           if(A[i]!=0)
  9.                dig=true;
  10.           if(dig) cout<<A[i];
  11.      }
  12.           cout<<"\n";
  13. }
  14. void Subtraction(int * A, int * B, int l)
  15. {
  16.      int borrow=0;
  17.      for(int i=l;i>=1;i--)
  18.      {
  19.           A[i]=A[i]-borrow;
  20.           if(A[i]<B[i])
  21.                A[i]=10+A[i],borrow=1;
  22.           A[i]=A[i]-B[i];
  23.      }
  24. }
  25. void DivisionByTwo(int * A, int l)
  26. {
  27.      int c=0;
  28.      for(int i=1;i<=l;i++)
  29.      {
  30.           A[i]=A[i]+c*10;
  31.           if(A[i]<2){
  32.                c=A[i];
  33.                A[i]=A[i]-c;
  34.           }
  35.           else{
  36.                c=A[i]%2;
  37.                A[i]=A[i]/2;
  38.           }
  39.      }
  40.   }
  41. void Julka(int* A, int* B, int * C,int l)
  42. {
  43.      Subtraction(A,B,l);
  44.      DivisionByTwo(A,l);
  45.      Subtraction(C,A,l);
  46.      Print(C,l);
  47.      Print(A,l);
  48. }
  49. int main()
  50. {
  51.      int A[101],B[101],C[101];
  52.     int t=10;
  53.     string k,tot;
  54.     while(t--){
  55.           cin>>tot>>k;
  56.           int l1=tot.length();
  57.           int l2=k.length();
  58.           int p=l2;
  59.           while(p!=l1){
  60.                k.insert(k.begin(),'0');
  61.                p++;
  62.           }
  63.           for(int i=1;i<=l1;i++)
  64.                A[i]=tot[i-1]-'0';
  65.           for(int i=1;i<=l1;i++)
  66.                B[i]=k[i-1]-'0';
  67.           for(int i=1;i<=l1;i++)
  68.                C[i]=A[i];
  69.           Julka(A,B,C,l1);
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement