Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <cstring>
- using namespace std;
- typedef int NrMare[1010];
- void AtribMic(NrMare x, int n)
- {
- x[0]=0;
- if(n==0)
- x[(x[0]=1)]=0;
- else
- for(;n;n/=10)
- x[++x[0]]=n%10;
- }
- void Adunare(NrMare x,NrMare y)
- // x = x + y
- {
- int i,t=0;
- if(x[0]<y[0])
- x[0]=y[0];
- for(i=1;i<=x[0];i++,t/=10)
- {
- t=x[i]+y[i]+t;
- x[i]=t%10;
- // echivalent x[i]=(t+=x[i]+y[i])%10
- }
- if(t)
- x[++x[0]]=t;
- }
- void Scadere(NrMare x, NrMare y)
- // x <-- x-y
- {
- int i,j;
- for (i = 1; i <= x[0]; i++)
- if(x[i]>=y[i])
- x[i]-=y[i];
- else
- {
- j=i+1;
- while(x[j]==0)
- x[j++]=9;
- x[j]--;
- x[i]=10+x[i]-y[i];
- }
- for (; x[0] > 1 && !x[x[0]]; x[0]--); // sa n-am zerouri nesemnificative
- }
- int Divide(NrMare x, int n)
- //x = x /n, returneaza x%n
- {
- int i,r=0;
- for(i=x[0];i>0;i--)
- {
- r=10*r+x[i];
- x[i]=r/n;
- r%=n;
- }
- for(;x[x[0]]==0 && x[0]>1;)
- x[0]--;
- return r;
- }
- ofstream g("numere20.out");
- void Afisare(NrMare n)
- {
- for(int i=n[0];i>0;--i)
- g<<n[i];
- g<<'\n';
- }
- int main ()
- {
- int u,v;
- char numar[101];
- NrMare n,npeu,npev,npeuxv;
- ifstream f("numere20.in");
- f>>numar;
- n[0]=strlen(numar);
- npeu[0]=n[0];
- npev[0]=n[0];
- npeuxv[0]=n[0];
- for(int k=0;k<n[0];++k)
- n[n[0]-k]=npeu[n[0]-k]=npev[n[0]-k]=npeuxv[n[0]-k]=numar[k]-'0';
- f>>u>>v;
- f.close();
- /// n-(n/u+n/v-n/(u*v))
- Divide(npeu,u);
- Divide(npev,v);
- Divide(npeuxv,u*v);
- Adunare(npeu,npev);
- Scadere(npeu,npeuxv);
- Scadere(n,npeu);
- Afisare(n);
- g.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement