
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s,s1;
cin>>s;
int a;
cin>>a;
s1.clear();
int t=s[0]-'0';
if(t>=a)
s1.push_back(t/a+'0');
int len=s.size();
int r=0;
for(int i=1;s[i];i++)
{
r=t%a;
t=r*10+s[i]-'0';
s1.push_back(t/a+'0');
}
if(len==1&&s[0]-'0'<a)
{
cout<<"0"<<" "<<s[0]-'0'<<endl;
}
else
cout<<s1<<" "<<t%a<<endl;
return 0;
}这题难是不难,主要是运用到除法 对于string又有新的认识
本文介绍了一种处理字符串与整数除法运算的方法,通过C++实现,详细讲解了如何将字符串中的数字逐位进行除法操作,并保留商和余数的过程。
1698

被折叠的 条评论
为什么被折叠?



