Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- ifstream fin("date.in");
- ofstream fout("date.out");
- int a[1000],b[1000];
- int main()
- {
- char c;
- while(fin>>c)
- {
- if(c>='0' && c<='9')
- {
- a[0]++;
- a[a[0]]=c-48;
- }
- else break;
- }
- int k;
- fin>>k;
- while(k)
- {
- b[0]++;
- b[b[0]]=k%10;
- k/=10;
- }
- for(int i=1;i<=a[0]/2;i++)
- {
- int aux=a[i];
- a[i]=a[a[0]-i+1];
- a[a[0]-i+1]=aux;
- }
- int transport=0;
- if(a[0]>b[0])
- {
- for(int i=1;i<=a[0];i++)
- {
- if(transport==1)
- {
- a[i]--;
- transport=0;
- }
- if(a[i]-b[i]<0)
- {
- transport=1;
- a[i]=a[i]+10-b[i];
- }
- else a[i]-=b[i];
- }
- for(int i=a[0];i>=1;i--)
- fout<<a[i];
- }
- else if(b[0]>a[0])
- {
- for(int i=1;i<=b[0];i++)
- {
- if(transport==1)
- {
- b[i]--;
- transport=0;
- }
- if(b[i]-a[i]<0)
- {
- transport=1;
- b[i]=b[i]+10-a[i];
- }
- else b[i]-=a[i];
- }
- for(int i=b[0];i>=1;i--)
- fout<<b[i];
- }
- else if(b[0]==a[0])
- {
- int oka=1,okb=1,okgen=1;
- for(int i=1;i<=b[0] && okgen==1;i++)
- {
- if(b[i]>a[i])
- {
- okb=0;
- okgen=0;
- }
- else
- {
- oka=0;
- okgen=0;
- }
- }
- if(oka==0)
- {
- for(int i=1;i<=a[0];i++)
- {
- if(transport==1)
- {
- a[i]--;
- transport=0;
- }
- if(a[i]-b[i]<0)
- {
- transport=1;
- a[i]=a[i]+10-b[i];
- }
- else a[i]-=b[i];
- }
- for(int i=a[0];i>=1;i--)
- fout<<a[i];
- }
- else
- {
- for(int i=1;i<=b[0];i++)
- {
- if(transport==1)
- {
- b[i]--;
- transport=0;
- }
- if(b[i]-a[i]<0)
- {
- transport=1;
- b[i]=b[i]+10-a[i];
- }
- else b[i]-=a[i];
- }
- for(int i=b[0];i>=1;i--)
- fout<<b[i];
- }
- }
- fin.close();
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement