Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <sstream>
- using namespace std;
- int toInt(string s){
- stringstream ss(s);
- int r;
- ss >> r;
- return r;
- }
- int multiply( int a, int b) {
- int wynik = 0;
- while (b > 0) {
- if (b & 1)
- wynik += a;
- a <<= 1;
- b >>= 1;
- }
- return wynik;
- }
- int main()
- {
- string a, b; int aInt, bInt;
- cin>>a>>b;
- size_t foundA = a.find(",");
- size_t foundB = b.find(",");
- bool isA = false, isB = false;
- if (a.find(",") != string::npos) {
- a.erase(foundA, 1); isA = true;
- }
- if (b.find(",") != string::npos) {
- b.erase(foundB, 1); isB = true;
- }
- aInt = toInt(a); bInt = toInt(b);
- if(aInt == 0 || bInt == 0){
- cout<<0<<endl;
- return 0;
- }
- int result = multiply(aInt, bInt);
- int comma = 0;
- if(isA){
- comma+=a.size()-foundA;
- }
- if(isB) {
- comma+=b.size()-foundB;
- }
- //cout<<comma<<endl;
- //cout<<comma<<endl;
- string s = to_string(result);
- if(s.size()< comma){
- cout<<"0,";
- }
- if(s.size()== comma){
- cout<<"0";
- }
- for(int i = 0; i <= s.size(); i++){
- if(s.size()-i == comma){
- cout<<",";
- }
- cout<<s[i];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement