本题为除法的模拟,如果简单暴力的去做,必定不行;注意细节要除去第一个为0的情况,并且注意最后输出时,字符串和数字应该分别输出
#include<cstdio>
#include<cstring>
const int maxn=1000+10;
using namespace std;
int main()
{
char s[maxn],out[maxn];
int x,rest=0;
//freopen("1017.txt","r",stdin);
scanf("%s %d",&s,&x);
for(int i=0;i<strlen(s);i++)
{
out[i]=((rest*10+s[i]-'0')/x)+'0';//计算除数
rest=(rest*10+s[i]-'0')%x;//计算余数
}
if(out[0]=='0'&&out[1]!=0)//避免首项为0的情况
printf("%s",out+1);
else
printf("%s",out);
printf(" %d\n",rest);
return 0;
}