A除以B

來源:互聯網
上載者:User

標籤:

連結:http://www.nowcoder.com/pat/6/problem/4043

題目描述
本題要求計算A/B,其中A是不超過1000位的正整數,B是1位正整數。你需要輸出商數Q和餘數R,使得A = B * Q + R成立。

 

輸入描述:
輸入在1行中依次給出A和B,中間以1空格分隔。



輸出描述:
在1行中依次輸出Q和R,中間以1空格分隔。

 

輸入例子:
123456789050987654321 7

 

輸出例子:
17636684150141093474 3

 1 #include "iostream" 2 #include <iomanip> 3 #include <string.h> 4 #include <string> 5 #include <vector> 6 #include <cmath> 7 #include <cctype> 8 #include <algorithm> 9 using namespace std;10 11 int d, r, i;12 int num1[1000];13 int num2[1000];14 char str[1000];15 int main()16 {    17     cin >>str >>d;18     for(i=0; i<strlen(str); ++i)19     {20         num1[i] = str[i]-‘0‘;21     }22     i=1;23     int k=0, tmp=num1[0];24     while(i < strlen(str))25     {26         tmp = tmp*10+num1[i++];27         if(tmp > d) break;28     }29     while(i <= strlen(str))30     {31         num2[k++] = tmp/d;32         tmp %= d;33         tmp = tmp*10+num1[i++];34     }35     r = tmp/10;36     for(int i=0; i<k; ++i)37     {38         cout <<num2[i];39     }40     cout <<" " <<r <<endl;41     return 0;42 }

 

A除以B

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.