Advertisement
CosminVarlan

Numere mari: +,-,*

Feb 21st, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. char a[1000], b[1000], c[1000];
  6.  
  7. void afiseaza(char v[])
  8. {
  9.     for(int i=0; i<strlen(v); i++)
  10.         cout<<v[i];
  11. }
  12.  
  13. void sum(char a[], char b[], char c[])
  14. {
  15.     strrev(a);
  16.     strrev(b);
  17.     for(int i=0; i<1000; i++)
  18.         c[i]=0;
  19.     for(int i=0; i<strlen(a); i++)
  20.         c[i]=a[i]-'0';
  21.  
  22.     for(int i=0; i<strlen(b); i++)
  23.         c[i]+=b[i]-'0';
  24.  
  25.     for(int i=0; i<999; i++)
  26.         if (c[i]>9){c[i]-=10; c[i+1]++;}
  27.     int firstzero=999;
  28.     while (c[firstzero]==0) firstzero--;
  29.     for(int i=0; i<=firstzero; i++)
  30.         c[i]+='0';
  31.     strrev(a);
  32.     strrev(b);
  33.     strrev(c);
  34. }
  35.  
  36. int mai_mare(char a[], char b[])
  37. {
  38.     if (strlen(a)>strlen(b))
  39.         return 1;
  40.     if(strlen(b)>strlen(a))
  41.         return 0;
  42.     if(strcmp(a, b)>0) return 1;
  43.     else return 0;
  44. }
  45.  
  46.  
  47. void scadere(char a[], char b[], char c[])
  48. {
  49.     for(int i=0; i<1000; i++)
  50.         c[i]=0;
  51.     if(mai_mare(a, b)==1)
  52.     {
  53.     strrev(a);
  54.     strrev(b);
  55.  
  56.     for(int i=0; i<strlen(a); i++)
  57.         c[i]=a[i]-'0';
  58.  
  59.     for(int i=0; i<strlen(b); i++)
  60.         c[i]-=b[i]-'0';
  61.  
  62.     for(int i=0; i<999; i++)
  63.         if (c[i]<0){c[i]+=10; c[i+1]--;}
  64.     int firstzero=999;
  65.     while (c[firstzero]==0) firstzero--;
  66.     for(int i=0; i<=firstzero; i++)
  67.         c[i]+='0';
  68.     strrev(a);
  69.     strrev(b);
  70.     strrev(c);
  71.     }
  72. }
  73.  
  74. void shift(char a[], int n)
  75. {
  76.     for(int i=998; i>=n ;i--)
  77.         a[i]=a[i-n];
  78.     for(int i=0; i<n; i++)
  79.         a[i]='0';
  80. }
  81.  
  82. void oriC(char a[], int n, char c[])
  83. {
  84.     for(int i=0; i<1000; i++)
  85.         c[i]=0;
  86.     strrev(a);
  87.     for(int i=0; i<strlen(a); i++)
  88.         c[i]=(a[i]-'0')*n;
  89.  
  90.     for(int i=0; i<strlen(a); i++)
  91.     {
  92.         int aux=c[i];
  93.         c[i]=c[i]%10;
  94.         c[i+1]+=aux/10;
  95.     }
  96.  
  97.     int firstzero=999;
  98.     while (c[firstzero]==0) firstzero--;
  99.     for(int i=0; i<=firstzero; i++)
  100.         c[i]+='0';
  101.     strrev(a);
  102.     strrev(c);
  103. }
  104.  
  105. void zero(char a[])
  106. {
  107.     for(int i=0; i<1000; i++)
  108.         a[i]=0;
  109. }
  110.  
  111. void makecopy(char a[], char b[])
  112. {
  113.     for(int i=0; i<1000; i++)
  114.             b[i]=a[i];
  115. }
  116.  
  117.  
  118. void ori(char a[], char b[], char c[])
  119. {
  120.     char temp[1000];
  121.     char temp2[1000];
  122.     char s[1000];
  123.     zero(temp);
  124.     zero(s);
  125.  
  126.     strrev(b);
  127.     for(int i=0; i<strlen(b); i++)
  128.     {
  129.         zero(temp);
  130.         zero(temp2);
  131.         oriC(a,b[i]-'0', temp);
  132.         strrev(temp);
  133.         shift(temp,i);
  134.         strrev(temp);
  135.         sum(s,temp,temp2);
  136.         makecopy(temp2, s);
  137.     }
  138.     makecopy(s, c);
  139. }
  140.  
  141. int main()
  142. {
  143.     cin.get(a, sizeof(a));
  144.     cin.get();
  145.     cin.get(b, sizeof(b));
  146.     ori(a, b, c);
  147.     afiseaza(c);
  148.     return 0;
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement