1017 A除以B

博客提供了题目链接https://pintia.cn/problem - sets/994805260223102976/problems/994805305181847552,同时转载了题解,题解来源为https://www.cnblogs.com/Gzu_zb/p/9546184.html。

题目链接:https://pintia.cn/problem-sets/994805260223102976/problems/994805305181847552

题解:

 1 #include <iostream>
 2 #include<string>
 3 using namespace std;
 4 const int MAXN = 1000 + 5;
 5 
 6 int main() {
 7     string str;
 8     int b;
 9     cin >> str >> b;
10     if (str[0] - 48 < b&&str.size() == 1) cout << 0 << " " << str[0];//比如3/8这种情况单独处理
11     else {
12         int ans[MAXN] = { 0 }, k = 0, temp = 0;
13         for (int i = 0; i < str.size(); i++) {
14             int cnt = temp * 10 + str[i] - 48;
15             ans[k++] = cnt / b;
16             temp = cnt % b;
17         }
18         if (ans[0] == 0)//首位是0不能输出
19             for (int i = 1; i < k; i++)
20                 cout << ans[i];
21         else
22             for (int i = 0; i < k; i++)
23                 cout << ans[i];
24         cout << " " << temp;
25     }
26     return 0;
27 }

 

转载于:https://www.cnblogs.com/Gzu_zb/p/9546184.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值