Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- #define pb push_back
- #define mp make_pair
- constexpr int N = (int)3000 + 111;
- constexpr int INF = (int)1e9 + 11;
- constexpr int md = (int)1e9+7;
- #pragma GCC optimize("O3")
- #pragma GCC optimize("unroll-loops")
- #pragma GCC target("avx2,popcnt")
- int total = 0;
- void normalize(string& s){
- if(s.find('.') == string::npos)
- return;
- int pos = s.find('.');
- while(s.back() == '0')
- s.pop_back();
- while(total >= 0 && s.size() - pos - 1 < total)
- s.push_back('0');
- if(s.back() == '.')
- s.pop_back();
- return;
- }
- void solve(){
- string A,B;
- cin >> A >> B;
- bool allIntegers = (A.find('.') == string::npos && B.find('.') == string::npos);
- double a = atof(A.c_str()), b = atof(B.c_str());
- for(int i = 0; i < A.size(); i++)
- if(A[i] == '.')
- total += (A.size() - i - 1);
- int cnt = 0;
- for(int i = 0; i < B.size(); i++)
- if(B[i] == '.')
- cnt = (B.size() - i - 1);
- total += cnt;
- vector<string> v;
- int mx = 0;
- mx = max(mx,(int)A.size());
- mx = max(mx,(int)B.size());
- int p = 0;
- vector<int> T;
- int S = total;
- for(int i = B.size()-1; i >= 0; i--){
- if(B[i] == '.'){
- continue;
- }
- double x = B[i] - '0';
- if(!allIntegers){
- if(cnt > 0)
- for(int j = 0; j < cnt; j++)
- x /= 10;
- else
- for(int j = 0; j < -cnt; j++)
- x *= 10;
- }
- cnt--;
- // cerr << "x*a: " << x*a << "\n";
- string C = to_string(x*a);
- normalize(C);
- if(C.find('.') == string::npos && (A.find('.') != string::npos || B.find('.') != string::npos))
- C.pb('.');
- if(x > 0){
- v.pb(C);
- T.pb(max(0ll,S-total));
- mx = max(mx,(int)C.size()+max(0ll,S-total));
- }
- if(!allIntegers)
- total = max(0ll,total-1);
- else
- total--;
- }
- string t = to_string(a*b);
- total = S;
- normalize(t);
- if(t.find('.') == string::npos && (A.find('.') != string::npos || B.find('.') != string::npos))
- t.pb('.');
- mx = max(mx,(int)t.size());
- for(int i = 0; i < mx - A.size(); i++)
- cout << " ";
- cout << A << "\n";
- for(int i = 0; i < mx - B.size(); i++)
- cout << " ";
- cout << B << "\n";
- for(int i = 0; i < mx; i++)
- cout << "-";
- cout << "\n";
- if(v.size() == 1){
- for(int j = 0; j < mx-t.size(); j++)
- cout << " ";
- cout << t << "\n";
- } else {
- for(int i = 0; i < v.size(); i++){
- for(int j = 0; j < mx-(int)v[i].size()-T[i]; j++)
- cout << " ";
- cout << v[i];
- for(int j = 0; j < T[i]; j++)
- cout << " ";
- cout << "\n";
- }
- for(int i = 0; i < mx; i++)
- cout << "-";
- cout << "\n";
- for(int j = 0; j < mx-t.size(); j++)
- cout << " ";
- cout << t;
- }
- return;
- }
- signed main(){
- ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
- int tests = 1;
- // cin >> tests;
- for(int test = 1; test <= tests; test++){
- solve();
- }
- return 0;
- }
- /**
- a[0] a[1] a[2] a[3] a[4] a[5] a[6]
- **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement