PAT 1017 A除以B (20 分)
作者:
昭明ZMing | 来源:发表于
2018-12-14 14:38 被阅读0次#include <iostream>
using namespace std;
int main() {
string s;
int a, t = 0, temp = 0;
cin >> s >> a;
int len = s.length();
t = (s[0] - '0') / a;//例210 7,s[0]为2.例84 7,s[0]为8
if ((t != 0 && len > 1) || len == 1)
cout << t;
temp = (s[0] - '0') % a;
for (int i = 1; i < len; i++) {
t = (temp * 10 + s[i] - '0') / a;
cout << t;
temp = (temp * 10 + s[i] - '0') % a;
}
cout << " " << temp;
return 0;
}
GitHub
本文标题:PAT 1017 A除以B (20 分)
本文链接:https://www.haomeiwen.com/subject/velghqtx.html
网友评论