Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- ifstream in("produsxl.in");
- ofstream out("produsxl.out");
- void citire(int a[])
- {
- in>>a[0];
- for(int i=1;i<=a[0];i++)
- {
- in>>a[a[0]-i+1];
- }
- }
- void prod(int a[],int cif,int b[],int s[],int nr)
- {
- int t=0,i,rez,j;
- b[0]=0;
- for(i=1;i<=a[0];i++)
- {
- rez=a[i]*cif+t;
- b[i]=rez%10;
- t=rez/10;
- b[0]++;
- }
- if(t)
- {
- b[0]++;
- b[b[0]]=t;
- }
- t=0;
- for(i=nr;i<=s[0];i++)
- {
- rez=s[i]+b[i-nr+1]+t;
- s[i]=rez%10;
- t=rez/10;
- }
- for(j=i-nr+1;j<=b[0];j++)
- {
- s[0]++;
- rez=b[j]+t;
- s[s[0]]=rez%10;
- t=rez/10;
- }
- if(t)
- {
- s[0]++;
- s[s[0]]=t;
- }
- }
- void afisare(int c[])
- {
- int i;
- for(i=c[0];i>=1;i--)
- out<<c[i];
- }
- int a[101],n,s[300],b[150];
- int main()
- {
- int k=0,cif,nr=0;
- citire(a);
- in>>n;
- while(n)
- {
- cif=n%10;
- n=n/10;
- nr++;
- prod(a,cif,b,s,nr);
- }
- afisare(s);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement