题目链接: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://pintia.cn/problem - sets/994805260223102976/problems/994805305181847552,同时转载了题解,题解来源为https://www.cnblogs.com/Gzu_zb/p/9546184.html。

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



