1017 A除以B

#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	vector<char>s1;
	vector<char>ans;
	int b;
	cin>>s>>b;
	if(s.size()==1){
		int k=s[0]-'0';
		if(k>=b){
			cout<<k/b<<" "<<k%b;
		}else{
			cout<<"0 "<<k;
		}
		return 0;
	}
	for(int i=0;i<s.size();i++){
		s1.push_back(s[i]);
	}
	int cnt=0;//保留倒数第二个余数 
	int pre=0;//保留前一个数 
	for(int i=0;i<s.size();i++){
		if(s1[i]-'0'>=b){
			int k=s1[i]-'0';
			k=cnt*10+k;
			cnt=k%b;
			pre=cnt;
			s1[i]=k%b+'0';
			k=k/b;
			ans.push_back(k+'0');
		
		}else{
			int k1=s1[i]-'0';
			//int k2=s1[i+1]-'0';
			k1=pre*10+k1;
			s1[i]=k1%b+'0';
			cnt=k1%b;
			pre=cnt;
			int k3=k1/b;
			ans.push_back(k3+'0');
		}
	}
//		int k1=cnt;
//			int k2=s1[s.size()-1]-'0';
//			k1=k1*10+k2;
//			cnt=k1%b;
//			int k3=k1/b;
//			ans.push_back(k3+'0');
	int r;
	r=cnt;
	int flag=0;
	for(int i=0;i<ans.size();i++){
		if(ans[i]!='0'&&flag==0){
			flag=1;
		}
		if(flag!=0)
		cout<<ans[i];
	}
	cout<<" "<<r;
}