PAT Basic 1017 A divided by B (20 minutes)

This problem requires calculation  /, where  A is not more than 1000 bit positive integer, B is a positive integer. You need to output quotient  Q and a remainder  R, such that  A = B × Q + R & lt established.

Input formats:

Given in one row sequentially input  A and  B, separated by an intermediate space.

Output formats:

In a row are sequentially output  Q and  R, separated by an intermediate space.

Sample input:

123456789050987654321 7

Sample output:

17636684150141093474 3


#include <iostream>
#include <vector>
using namespace std;
int main(){
    string s;int b,mid=0;
    vector<int> res;
    cin>>s>>b;
    bool start=false;
    for(int i=0;i<s.length();i++){
        mid+=(s[i]-'0');
        res.push_back(mid/b);
        mid=mid%b*10;
    }
    for(int i=0;i<res.size();i++){
        if(res[i]>0&&res[i]<=9) start=true;
        if(start) cout<<res[i];
    }
    if(!start) cout<<0;
    cout<<" "<<mid/10;
    system("pause");
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/littlepage/p/11372161.html