Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- string a,b,d;
- char c[100005];
- void dod()
- {
- int prz=0;
- for(int i=a.size()-1;i>=0;i--)
- {
- c[i]=((int)a[i]-48+(int)b[i]-48+prz)%10+48;
- prz=((int)a[i]-48+(int)b[i]-48+prz)/10;
- }
- }
- void odj()
- {
- for(int i=a.size()-1;i>=0;i--)
- {
- if((int)a[i]>=(int)b[i])
- c[i] = (int)a[i] - (int)b[i] + 48;
- else
- {
- for(int j=i-1;j>=0;j--)
- {
- if(a[j]>0)
- {
- a[j]=int(a[j])-1;
- for (int k=j; k<i-1; k++)
- {
- a[k+1] = 48+9;
- }
- c[i]=10+(int)a[i]-(int)b[i]+48;
- break;
- }
- }
- }
- }
- }
- void wypisz()
- {
- int j=0;
- while(c[j]=='0')
- j++;
- for(int i=j;i<a.size();i++)
- {
- cout << c[i];
- }
- }
- bool comp()
- {
- for(int i=0;i<a.size();i++)
- {
- if(a[i]<b[i])
- {
- return 0;
- }
- }
- return 1;
- }
- int main()
- {
- cin >> a >> b;
- cout << b << " ";
- int co;
- if(a[0]=='-')
- {
- if(b[0]=='-')
- {
- b=b.substr(1,b.length());
- a=a.substr(1,a.length());
- co=1;
- }
- else
- {
- a=a.substr(1,a.length());
- co=2;
- }
- }
- else{
- if(b[0]=='-')
- {
- b=b.substr(1,b.length());
- co=3;
- }
- else{
- co=1;
- }
- }
- cout << b << " ";
- if(b.size()>=a.size())
- b=string("0") + b;
- else
- a=string("0") + a;
- while(b.size()>a.size())
- {
- a=string("0") + a;
- }
- while(a.size()>b.size())
- {
- b=string("0") + b;
- }
- cout << b << " ";
- if(co!=1)
- {
- b=b.substr(1,b.length());
- a=a.substr(1,a.length());
- }
- cout << b << " ";
- if(co==1)
- {
- dod();
- }
- else
- {
- if(comp()==1)
- {
- odj();
- if(co==2)
- cout << '-';
- }
- else
- {
- d=a;
- a=b;
- b=d;
- odj();
- if(co==3)
- cout << '-';
- }
- }
- wypisz();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement