11576번 - Base Conversion
죽을꺼같아요 도와주세요 ㅠㅠ 왜틀린지를 모르겠어요
#include <iostream>#include<algorithm>#include <string>using namespace std;
int main(void) { string ans = ""; int A, B, n; int total = 0; int x = 1;
cin >> A >> B; cin >> n;
for(int i=0; i<n; i++) { int ex; cin >> ex; total = total * A + ex; } if (n == 1 && total == 0) cout << '0';
while (total) { int moc = total / B; int nam = total % B;
ans += nam+'0'; total = moc; } reverse(ans.begin(), ans.end());
for (int i = 0; i < ans.size(); i++) { cout << ans[i] << " "; }
return 0;
}
댓글을 작성하려면 로그인해야 합니다.
elanvpdls 6년 전
죽을꺼같아요 도와주세요 ㅠㅠ 왜틀린지를 모르겠어요
#include <iostream>
#include<algorithm>
#include <string>
using namespace std;
int main(void) {
string ans = "";
int A, B, n;
int total = 0;
int x = 1;
cin >> A >> B;
cin >> n;
for(int i=0; i<n; i++) {
int ex;
cin >> ex;
total = total * A + ex;
}
if (n == 1 && total == 0)
cout << '0';
while (total) {
int moc = total / B;
int nam = total % B;
ans += nam+'0';
total = moc;
}
reverse(ans.begin(), ans.end());
for (int i = 0; i < ans.size(); i++) {
cout << ans[i] << " ";
}
return 0;
}