补全9月11日至13日课评:为13名学生创建请假文档,为5个班级创建总结文档
This commit is contained in:
37
C++代码/CSP04/01/小杨的进制数位.cpp
Normal file
37
C++代码/CSP04/01/小杨的进制数位.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int num, k;
|
||||
string out;
|
||||
string S = "0123456789ABCDEF";
|
||||
int cnt1 = 0,cnt2 = 0;
|
||||
|
||||
int main(){
|
||||
cin >> num >> k;
|
||||
|
||||
if(num == 0){
|
||||
cout << 0 << endl << 1 << endl << 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int t = num;
|
||||
while(t > 0){
|
||||
int g = t % k;
|
||||
|
||||
out = S[g] + out;
|
||||
|
||||
t /= k;
|
||||
}
|
||||
|
||||
for(char c : out){
|
||||
if(isupper(c)){
|
||||
cnt2++;
|
||||
}else if(isdigit(c)){
|
||||
cnt1++;
|
||||
}
|
||||
}
|
||||
cout << out << endl << cnt1 << endl << cnt2;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user