Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- char a[1000], b[1000], c[1000];
- void afiseaza(char v[])
- {
- for(int i=0; i<strlen(v); i++)
- cout<<v[i];
- }
- void sum(char a[], char b[], char c[])
- {
- strrev(a);
- strrev(b);
- for(int i=0; i<1000; i++)
- c[i]=0;
- for(int i=0; i<strlen(a); i++)
- c[i]=a[i]-'0';
- for(int i=0; i<strlen(b); i++)
- c[i]+=b[i]-'0';
- for(int i=0; i<999; i++)
- if (c[i]>9){c[i]-=10; c[i+1]++;}
- int firstzero=999;
- while (c[firstzero]==0) firstzero--;
- for(int i=0; i<=firstzero; i++)
- c[i]+='0';
- strrev(a);
- strrev(b);
- strrev(c);
- }
- int mai_mare(char a[], char b[])
- {
- if (strlen(a)>strlen(b))
- return 1;
- if(strlen(b)>strlen(a))
- return 0;
- if(strcmp(a, b)>0) return 1;
- else return 0;
- }
- void scadere(char a[], char b[], char c[])
- {
- for(int i=0; i<1000; i++)
- c[i]=0;
- if(mai_mare(a, b)==1)
- {
- strrev(a);
- strrev(b);
- for(int i=0; i<strlen(a); i++)
- c[i]=a[i]-'0';
- for(int i=0; i<strlen(b); i++)
- c[i]-=b[i]-'0';
- for(int i=0; i<999; i++)
- if (c[i]<0){c[i]+=10; c[i+1]--;}
- int firstzero=999;
- while (c[firstzero]==0) firstzero--;
- for(int i=0; i<=firstzero; i++)
- c[i]+='0';
- strrev(a);
- strrev(b);
- strrev(c);
- }
- }
- void shift(char a[], int n)
- {
- for(int i=998; i>=n ;i--)
- a[i]=a[i-n];
- for(int i=0; i<n; i++)
- a[i]='0';
- }
- void oriC(char a[], int n, char c[])
- {
- for(int i=0; i<1000; i++)
- c[i]=0;
- strrev(a);
- for(int i=0; i<strlen(a); i++)
- c[i]=(a[i]-'0')*n;
- for(int i=0; i<strlen(a); i++)
- {
- int aux=c[i];
- c[i]=c[i]%10;
- c[i+1]+=aux/10;
- }
- int firstzero=999;
- while (c[firstzero]==0) firstzero--;
- for(int i=0; i<=firstzero; i++)
- c[i]+='0';
- strrev(a);
- strrev(c);
- }
- void zero(char a[])
- {
- for(int i=0; i<1000; i++)
- a[i]=0;
- }
- void makecopy(char a[], char b[])
- {
- for(int i=0; i<1000; i++)
- b[i]=a[i];
- }
- void ori(char a[], char b[], char c[])
- {
- char temp[1000];
- char temp2[1000];
- char s[1000];
- zero(temp);
- zero(s);
- strrev(b);
- for(int i=0; i<strlen(b); i++)
- {
- zero(temp);
- zero(temp2);
- oriC(a,b[i]-'0', temp);
- strrev(temp);
- shift(temp,i);
- strrev(temp);
- sum(s,temp,temp2);
- makecopy(temp2, s);
- }
- makecopy(s, c);
- }
- int main()
- {
- cin.get(a, sizeof(a));
- cin.get();
- cin.get(b, sizeof(b));
- ori(a, b, c);
- afiseaza(c);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement