补全9月11日至13日课评:为13名学生创建请假文档,为5个班级创建总结文档
This commit is contained in:
40
C++代码/CSP04/01/小杨的幸运数字.cpp
Normal file
40
C++代码/CSP04/01/小杨的幸运数字.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n, num, cnt = 0, sum = 0;
|
||||
string str = "01";
|
||||
|
||||
int main() {
|
||||
cin >> n;
|
||||
|
||||
for(int i = 1; i <= n; i++) {
|
||||
cin >> num;
|
||||
int t = num;
|
||||
|
||||
string out = "";
|
||||
int cnt1 = 0;// 判断1的个数
|
||||
|
||||
while(t > 0) {
|
||||
int g = t % 2;
|
||||
|
||||
if(g == 1){
|
||||
sum++; // 总数加一
|
||||
cnt1++; // 个数加一
|
||||
}
|
||||
|
||||
out = str[g] + out;
|
||||
t /= 2;
|
||||
}
|
||||
|
||||
if(cnt1 == 1){
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
|
||||
cout << cnt << endl << sum;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user