pat1017

这道题要考虑下只有一个数字的情况,还有数字的第一个字母不能为0;

代码如下:

#include <iostream>
#include<cstdio>
using namespace std;
#include<string>

int main()
{
   string a,q;
   int b,r;
   cin>>a>>b;
   int temp=(a[0]-'0')/b;
   if(temp>0)
   q.push_back(temp+'0');
     r=(a[0]-'0')%b;
   for(int i=1;i<a.length();i++)
  {
  
    temp=(a[i]+r*10-'0')/b;
    r=(a[i]+r*10-'0')%b;
    q.push_back(temp+'0');
  }  
  
  if(a.length()==1&&(a[0]-'0')<b)
    cout<<0<<" "<<r<<endl;
    else 
    cout<<q<<" "<<r<<endl;
    return 0;
}

posted on 2017-07-02 09:30  想去浙大的读研wzp  阅读(181)  评论(0编辑  收藏  举报

导航