官方题解|欢乐赛 #35
2024-12-16 15:07:14
发布于:浙江
欢乐赛35 官方题解
T1
先读入整数 ,然后再输出 即可。
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
cout << n + 114514;
return 0;
}
T2
先读入 个数,然后定义一个存储偶数出现的次数,记得初始化为 ,如果当前的数是偶数,那么加一,最后输出 。
#include <bits/stdc++.h>
using namespace std;
int n, a[110];
int main(){
int n, cnt = 0;
cin >> n;
for(int i = 1; i <= n; i ++){
cin >> a[i];
if(a[i] % 2 == 0) cnt ++;
}
cout << cnt;
return 0;
}
T3
本题考查数位分离,只需要把 数位分离,统计有多少位是6即可。
#include <bits/stdc++.h>
using namespace std;
int n, cnt;
int main(){
cin >> n;
while(n){
if(n % 10 == 6) cnt ++;
n /= 10;
}
cout << cnt;
return 0;
}
T4
首先要明白主对角线上方的元素有哪些,很明显满足一个性质:,所以只要看满足 的位置中有没有 ,如果有,直接输出 ,如果找不到输出 。
#include <bits/stdc++.h>
using namespace std;
int n;
int a[110][110];
int main(){
cin >> n;
for(int i = 1; i <= n; i ++ )
for(int j = 1; j <= n; j ++){
cin >> a[i][j];
if(i < j && a[i][j] != 0){
cout << "NO\n";
return 0;
}
}
cout << "YES\n";
return 0;
}
T5
本题先读入 然后利用一个小技巧,s = " " + s
,这样 的下标就从 开始了,所以我们只需要输出下标从 的字符即可。
#include <bits/stdc++.h>
using namespace std;
int main(){
string s;
int a, b;
cin >> s >> a >> b;
s = " " + s;
for(int i = a; i <= b; i ++ ){
cout << s[i];
}
return 0;
}
T6
先把十进制数 转化为八进制数存在一个集合里面,然后在把那个集合的数看作十六进制数,然后只要按照十六进制转十进制的方法转化一次即可。
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
vector<int>q;
while(n){
q.push_back(n % 8);
n /= 8;
}
int sum = 0;
int x = 1;
for(int i = 0; i < q.size(); i ++ ){
sum += x * q[i];
x *= 16;
}
cout << sum;
return 0;
}
全部评论 2
这欢乐赛咋这么臭(悲)!
2024-12-14 来自 广东
0因为没喷香水
2024-12-16 来自 浙江
06
2025-03-15 来自 江西
0
老师,您发灌水池塘里了···
2024-12-14 来自 北京
0哈哈
2024-12-14 来自 浙江
0
有帮助,赞一个