写c++还是皮皮虾团队内部赛J1-H题解
2025-04-07 19:23:02
发布于:湖北
个人难度:红红红红红红红橙橙
官方难度:红红红红红?红橙黄
T1
经典题目,非常简单
#include <iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
cout << a + b;
return 0;
}
T2
两重for + if判断
可以用两个数组存相对坐标(dx和dy)
最后注意检测(第22行)
#include <iostream>
using namespace std;
const int N = 110;
int n, m;
char g[N][N];
int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
userId_undefined
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> g[i];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if (g[i][j] == '?') {
int cnt = 0;
for (int k = 0; k < 8; k++) {
int x = i + dx[k], y = j + dy[k];
userId_undefined
if (x >= 0 && x < n && y >= 0 && y < m && g[x][y] == '*') cnt++ ;
}
g[i][j] = cnt + '0';
}
for (int i = 0; i < n; i++) cout << g[i];
return 0;
}
T3, T4, T5都是最简单的输出,直接上代码(这里为了方便用的是PY)
T3
print("Hello World! I'm a C++ program.")
T4
print("Hello world")
T5
print('''Nice to meet you
Nice to meet you too''')
T6 这题是数学题,令人尴尬的是本蒟蒻数学很菜所以直接下一道
(此时队长坐不住了)
#include <iostream>
using namespace std;
int main() {
for (int A = 1; A <= 9; ++A) {
for (int B = 0; B <= 9; ++B) {
for (int C = 0; C <= 9; ++C) {
for (int D = 0; D <= 9; ++D) {
int num = A * 10000000 + 2 * 1000000 + B * 100000 + 0 * 10000 + C * 1000 + 2 * 100 + D * 10 + 4;
if ((D * 10 + 4) % 8 == 0) {
int digitSum = A + 2 + B + 0 + C + 2 + D + 4;
if (digitSum % 9 == 0) {
cout << num << endl;
return 0;
}
}
}
}
}
}
return 0;
}
T7
这道题目直接求积然后数字逆序即可
注意不能用to_string()再字符串逆序,因为会有前导0
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int c = a * b;
int sum = 0;
while (c > 0) {
sum = sum * 10 + c % 10;
c /= 10;
}
cout << sum;
return 0;
}
T8
重点是质数判断,剩下的就好做了
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
bool prime(int x);
int main() {
string str;
int a[26] = {0};
int max = 0, min = 9999;
cin >> str;
for (int i = 0; i < str.length(); i++) a[str[i] - 'a'] += 1;
for (int i = 0; i < 26; i++) {
if (max < a[i]) max = a[i];
if (min > a[i] && a[i] != 0) min = a[i];
}
if (prime(max - min)) cout << "Lucky Word" << endl << (max - min) << endl;
else cout << "No Answer" << endl << 0 << endl;
return 0;
}
bool prime(int x) {
if(x < 2) return false;
else for(int i = 2; i <= sqrt(x); i++) if(x % i == 0) return false;
return true;
}
T9
个人认为最难的题
主要思路就是按输入顺序一个个按照循环次数减一,直到减成0换到下一位
#include <iostream>
using namespace std;
int s[11000], ans;
int main() {
int n, m; cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> s[i];
int t = m + 1;
while (t <= n + m) {
for (int i = 1; i <= m; i++) {
s[i]--;
if (s[i] == 0) {
s[i] = s[t];
t++;
}
}
userId_undefined
ans++;
}
cout << ans;
return 0;
}
感谢:
题解人@古希腊掌管AC和WA的神
队长@忘川秋库
全部评论 2
你们人数!
我们s了……5天前 来自 浙江
0?
5天前 来自 上海
0他们人数生长太快了
5天前 来自 浙江
0嘿嘿(奸笑
4天前 来自 上海
0
T6:12003264
6天前 来自 湖北
0
有帮助,赞一个