Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream fin("baza.in");
- ofstream fout("baza.out");
- vector<int> x, y, z;
- char numere[1001];
- vector<int> adunare_numere_mari(vector<int> x, vector<int> y)
- {
- vector<int> rez;
- int l = x.size(), t = 0, r = 0;
- for(int i = 0; i < l; i++)
- {
- r = x[i] + y[i] + t;
- rez.push_back(r % 10);
- t = r / 10;
- }
- if(t)
- {
- rez.push_back(t);
- }
- return rez;
- }
- vector<int> inmultire_scalar(vector<int> x, int s )
- {
- int t = 0;
- vector<int> rez;
- for(int i = 0; i < x.size(); i++)
- {
- int r = x[i] * s + t;
- rez.push_back(r % 10);
- t = r / 10;
- }
- while(t)
- {
- rez.push_back(t % 10);
- t /= 10;
- }
- return rez;
- }
- vector<int> inmultire_numere_mari(vector<int> x, vector<int> y)
- {
- int t = 0, marime = x.size() + y.size() - 1;
- vector<int> rez;
- rez.resize(marime);
- for(int i = 0; i < x.size(); i++)
- {
- for(int j = 0; j < y.size(); j++)
- {
- rez[i+j] += x[i] * y[j];
- }
- }
- for(int i = 0; i < marime; i++)
- {
- int r = t + rez[i];
- rez[i] = r % 10;
- t = r / 10;
- }
- while(t)
- {
- rez.push_back(t % 10);
- t /= 10;
- }
- return rez;
- }
- vector<int> scadere_numere_mari(vector<int> x, vector<int> y)
- {
- int t = 0;
- vector<int> rez;
- for(int i = 0; i < x.size(); i++)
- {
- int r = x[i] - y[i] - t;
- if(r < 0)
- r += 10, t = 1;
- else
- t = 0;
- rez.push_back(r);
- }
- while(t)
- {
- rez.push_back(t % 10);
- t /= 10;
- }
- while(rez.back() == 0 && rez.size() > 1)
- rez.pop_back();
- return rez;
- }
- vector<int> impartire_scalar(vector<int> x, int s)
- {
- int t = 0;
- vector<int> rez;
- for(int i = x.size()-1; i >= 0; i--)
- {
- int r = t * 10 + x[i];
- rez.push_back(r / s);
- t = r % s;
- }
- return rez;
- /// pentru imparire nu mai inversez vectorul
- }
- void afisare(vector<int> a)
- {
- for(const auto it : a)
- if(it > 9)
- fout << char(it - 10 + 65);
- else
- fout << it;
- fout << '\n';
- }
- int main()
- {
- fin >> numere;
- for(int i = 0; i < strlen(numere); i++)
- if(isdigit(numere[i]))
- x.push_back(numere[i]-'0');
- else
- x.push_back(numere[i] - 65 + 10);
- fin >> numere;
- for(int i = 0; i < strlen(numere); i++)
- if(isdigit(numere[i]))
- y.push_back(numere[i] - '0');
- else
- y.push_back(numere[i] - 65 + 10);
- reverse(x.begin(), x.end());
- reverse(y.begin(), y.end());
- while(x.size() < y.size())
- x.push_back(0);
- while(y.size() < x.size())
- y.push_back(0);
- afisare(x);
- afisare(y);
- //z = adunare_numere_mari(x, y);
- //z = inmultire_scalar(x, 2);
- //z = inmultire_numere_mari(x, y);
- //z = scadere_numere_mari(x, y);
- z = impartire_scalar(x, 2);
- //reverse(z.begin(), z.end());
- afisare(z);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement