文章
27
粉丝
86
获赞
10
访问
30.4k
C++
注意前导0
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(){
string AS;
int B;
while(cin >> AS >> B){
vector<char> A;
for(int i = 0; i < AS.size(); i++){
A.push_back(AS[i]);
}
vector<int> Q;
int R;
int carry = 0;
for(int i = 0; i < AS.size(); i++){
carry = carry * 10 + A[i] - '0';
if(i == 0 && carry / B == 0){
continue;
}
Q.push_back(carry / B);
carry %= B;
}
R = carry;
int index = 0;
while(index < Q.size() && Q[index] == 0){
index++;
}
for(; index < Q.size(); index++){
cout << Q[index];
}
cout << " " << R << endl;
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发