Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- const int NMAX = 1000;
- int main(int argc,char* argv[]) {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- ///
- string a,b;
- cin >> a >> b;
- vector<int> A(NMAX,0),B(NMAX,0),C(NMAX,0),ANS(NMAX,0);
- int j = 0;
- for(int i = a.size() - 1; i >=0; i--) {
- A[j] = a[i]-'0';
- j++;
- }
- j = 0;
- for(int i = b.size() - 1; i >=0; i--) {
- B[j] = b[i]-'0';
- j++;
- }
- for(int i = 0; i <= NMAX; i++){
- int f;
- int s = A[i] - B[i] - C[i];
- if(s < 0){
- ANS[i] = A[i] + 10 - B[i] - C[i];
- C[i+1] = 1;
- }
- else ANS[i] = s;
- }
- int f=NMAX;
- while(ANS[f] == 0){
- f--;
- }
- if(f == -1){
- cout << 0;
- return 0;
- }
- for(int i = f; i >=0; i--) cout << ANS[i];
- ///
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement