1017 A除以B (20 分)
#include <iostream> #include <string> using namespace std; int main() { string num; int a, b, m; cin >> num >> m; // 一个为字符串一个为整形数字避免了麻烦的处理 int len = num.size(); a = (num[0] - '0') / m; b = (num[0] - '0') % m; if (len == 1 || (len > 1 && a != 0)) // 判断数字的第一个是否为零,位数为1的情况,不为1的情况 cout << a; for (int i = 1; i < len; i++) { a = (b * 10 + (num[i] - '0')) / m; cout << a; b = (b * 10 + (num[i] - '0')) % m; } cout << " " << b; return 0; }