暑期训练题单1.习题总结
这里只写了我写完的
P9516 color
思路
这题主要是考数学的。(大水题)
给你5个评估洛谷的咕值的分数
求这个账号的人的名字颜色是什么
我们这里可以看官发的洛谷咕值系统介绍,其中说明了
灰名:0~99
蓝名:100~119
绿名:120~169
橙名:170~229
红名:230~500
由此做题思路就来了:
- 输入5个用来评估的分数
- 把5个分数都相加起来
- 最后判断分数在哪一个
阶层等级
代码
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 2;
const int N1 = 1e3 + 2;
typedef long long ll;
typedef unsigned long long ull;
signed main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int a, b, c, d, e, n;
cin >> a >> b >> c >> d >> e;
n = a + b + c + d + e;
if (n < 100) {
cout << "Gray\n";
} else if (n >= 100 && n < 120) {
cout << "Blue\n";
} else if (n >= 120 && n < 170) {
cout << "Green\n";
} else if (n >= 170 && n < 230) {
cout << "Orange\n";
} else {
cout << "Red\n";
}
return 0;
}
P1957 口算练习题
思路
这题跟上一题一样,都是大水题+数学,只不过还要模拟。
一共有 \(T\) 行数据。
\(T+1\) 行输入要么1字符+两数字,要么就只有两数字。
中间的输入要先输入字符串,因为不确定为哪种情况。
最后确定了还要把字符转数字(情况一)。
情况有两种:
- 两数字。默认就为加法,输出两个整数相加的式子。
- 就得按字符的情况来:‘a’为加法,‘b’为减法,‘c’为乘法。然后输出两个整数进行操作的式子。
中途计算的时候还要把数字转字符串和字符串转数字。
最后输出完,直接return 0;结束就可以了。
虽然本人都有点忘了当时怎么写出来的
代码
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 2;
typedef unsigned long long ull;
typedef long long ll;
typedef unsigned int ui;
int test(int n)
{
int sum = 0;
while (n)
sum++, n /= 10;
return sum;
}
string i_t_s(int x)
{
string ans;
if (x == 0)
return "0";
int y = x;
x = abs(x);
while (x)
ans = char(x % 10 + '0') + ans, x /= 10;
if (y < 0)
ans = '-' + ans;
return ans;
}
int s_t_i(string a)
{
int sum = 0;
for (int i = 0; i < a.length(); i++)
sum = sum * 10 + (a[i] - '0');
return sum;
}
int main()
{
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int T;
string a;
char b;
ll n, m, sum;
string s;
cin >> T;
while (T--)
{
cin >> a;
if (a[0] >= 'a' && a[0] <= 'c')
{
b = a[0];
cin >> n >> m;
}
else
{
cin >> m;
n = s_t_i(a);
}
int n1 = test(n), m1 = test(m);
if (b == 'a')
{
s = i_t_s(n) + '+' + i_t_s(m) + '=' + i_t_s(n + m);
cout << s << '\n';
cout << s.length() << '\n';
}
else if (b == 'b')
{
s = i_t_s(n) + '-' + i_t_s(m) + '=' + i_t_s(n - m);
cout << s << '\n';
cout << s.length() << '\n';
}
else if (b == 'c')
{
s = i_t_s(n) + '*' + i_t_s(m) + '=' + i_t_s(n * m);
cout << s << '\n';
cout << s.length() << '\n';
}
}
return 0;
}
P1055 [NOIP2008 普及组] ISBN 号码
思路
这道题十分经典,本人都考了7,8次。
这题就是输入字符串,把前面的数字按照顺序乘起来(指→ \(数字*顺序+下一个数字*(顺序+1)+……\)))。
最后看最后一个数字符不符合乘积%11。
如果一样,输出Right,
否则输出正确的编码。
小提示:
如果%11==10,则是'X'来表示,在判断和输出时都要考虑这种情况,否则分数会≤50。
代码
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 2;
const int N1 = 1e3 + 2;
typedef long long ll;
typedef unsigned long long ull;
#define fo(i,n,m) for(int i=n;i<=m;i++)
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
string a = "";
int sum = 0, tount = 1;
cin >> a;
int len = a.length();
for (int i = 0; i <= len - 3; i++) {
if (a[i] != '-') {
sum += (a[i] - '0') * tount;
tount++;
}
}
sum %= 11;
if (int(a[len - 1] - '0') == sum || (a[len - 1] == 'X' && sum == 10)) {
cout << "Right\n";
return 0;
}
for (int i = 0; i <= len - 2; i++) {
cout << a[i];
}
if (sum == 10) {
cout << "X\n";
} else {
cout << char(sum + '0') << '\n';
}
return 0;
}
B3843 [GESP202306 三级] 密码合规
思路
这题在我打GESP202403的时候都还没有打出来
这题主要是字符串模拟+高强度if判断。
首先要先输入,
然后读出来每个密码,
最后判断就行了。
判断条件:
- 字符为 \(a ~ z\),\(A ~ Z\),\(0 ~ 9\),
!@#$。- $6 ≤ len(程度)≤ 12
- 大小写、数字各两个,特殊字符(指→
!@#$)之中要有一个
小提示:
这题输入不要用
getline,否则有些字符串读不出来
代码
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 2;
const int N1 = 1e3 + 2;
typedef long long ll;
typedef unsigned long long ull;
#define fo(i,n,m) for(int i=n;i<=m;i++)
bool isss(string a) {
int da = 0, xiao = 0, shu = 0, zi = 0;
fo(i, 0, a.length() - 1) {
if (a[i] >= 'A' && a[i] <= 'Z')
da++;
else if (a[i] >= 'a' && a[i] <= 'z')
xiao++;
else if (a[i] >= '0' && a[i] <= '9')
shu++;
else
zi++;
}
int f = bool(da) + bool(xiao) + bool(shu);
if (f >= 2 && zi >= 1)
return 1;
return 0;
}
bool iss(string a) {
if ((a.size() >= 6 && a.size() <= 12) == 0)
return 0;
fo(i, 0, a.length() - 1) {
if ((a[i] >= 'A' && a[i] <= 'Z') == 0 && (a[i] >= 'a' && a[i] <= 'z') == 0 && (a[i] >= '0' && a[i] <= '9') == 0
&& a[i] != '!' && a[i] != '@' && a[i] != '#' && a[i] != '$')
return 0;
}
if (isss(a))
return 1;
return 0;
}
int main() {
//ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
string a, c;
cin >> a;
fo(i, 0, a.length() - 1) {
if (a[i] == ',') {
if (iss(c))
cout << c << '\n';
c = "";
} else if (i == a.length() - 1) {
c += a[i];
if (iss(c))
cout << c << '\n';
break;
} else
c += a[i];
}
return 0;
}
B3911 [语言月赛 202312] 铅球杯
思路
这题打一个map就可以了。
输入部分:赋值 + 使用
前期你就输入一个字符串,一个数字,然后丢个map赋值
后面是输出,如果为{,打上标记。
如果标记在,拿个字符串存一下。
最后为},把标记取消,输出在map存储的数据。
如果都不是,则继续输出。
代码
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 2;
const int N1 = 1e3 + 2;
typedef long long ll;
typedef unsigned long long ull;
#define int long long
int n, k, t;
map<string, int> q;
string a, m;
int b;
signed main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a >> b;
q[a] = b;
}
cin.get();
for (int i = 0; i <= k; i++) {
m = "";
getline(cin, a);
bool f = 0;
int len = a.length();
for (int j = 0; j < len; j++) {
if (a[j] == '{') {
f = 1;
continue;
} else if (a[j] == '}') {
f = 0;
cout << q[m];
m = "";
continue;
}
if (f) {
m += a[j];
continue;
}
cout << a[j];
}
cout << '\n';
}
return 0;
}
B2113 输出亲朋字符串
思路
这个不能简单到再简单了。
先输入个字符串,
然后循环便利,
如果这个 \(i\) 为长度-1,加a[0],否则 + a[i + 1]。
最后直接输出字符串就可以了
代码
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 2;
const int N1 = 1e3 + 2;
typedef long long ll;
typedef unsigned long long ull;
#define fo(i,n,m) for(int i=n;i<=m;i++)
#define fost(i,n,a) for(int i=n;i<=a.length();i++)
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
string a;
cin >> a;
string b = a;
for (int i = 0; i < a.length(); i++)
if (i == a.length() - 1)
a[i] += b[0];
else
a[i] += b[i + 1];
cout << a;
return 0;
}
P1200 [USACO1.1] 你的飞碟在这儿 Your Ride Is Here
思路
这个跟上一题一模一样简单。
就是乘字母的顺序。
实现方法:int ans = 1; for(...) { ans *= (a[i] - 'A' + 1); }
'A'+1是求出他的字母顺序。
ans = 1;因为如果是0,乘积的答案就永远为0。
最后比大小就可以。
代码
//很久以前的代码风格,别喷
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef char ch;
typedef void vo;
typedef int nt;
typedef double le;
typedef string ing;
nt main() {
ios::sync_with_stdio(0), cin.tie(0);
ing k, s;
nt sum = 1, num = 1;
cin >> k >> s;
for (nt i = 0 ; i < k.length() ; i++ ) sum *= k[i] - '@' ;
for (nt i = 0 ; i < s.length() ; i++ ) num *= s[i] - '@' ;
sum %= 47;
num %= 47;
if (sum != num) {
cout << "STAY";
return 0;
} else {
cout << "GO";
return 0;
}
}
P1321 单词覆盖还原
思路
这题更简单。
输入字符串,如果有boy或者girl就直接++。
最后比大小就可以了。
代码
//很久以前的代码风格,别喷
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef char ch;
typedef void vo;
typedef int nt;
typedef double le;
typedef string ing;
nt main() {
ios::sync_with_stdio(0), cin.tie(0);
string a;
nt na = 0, nu = 0;
cin >> a;
for (nt i = 0; i < a.length(); i++) {
if (a[i] == 'b' || a[i + 1] == 'o' || a[i + 2] == 'y') {
na++;
}
if (a[i] == 'g' || a[i + 1] == 'i' || a[i + 2] == 'r' || a[i + 3] == 'l') {
nu++;
}
}
cout << na << endl << nu << endl;
return 0;
}
[ABC009A] 引越し作業
思路
AT远古老题。
一个数字,要么 \(-1\) ,要么 \(-2\),问减去的最少次数。
肯定先 \(-2\),如果有剩的,再 \(-1\)。
代码
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 2;
const int N1 = 1e3 + 2;
typedef long long ll;
typedef unsigned long long ull;
signed main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n;
cin >> n;
cout << n / 2 + n % 2 << '\n';
return 0;
}
[ABC009B] 心配性な富豪、ファミリーレストランに行く。
思路
求第二个大的数。
可以用sort快排,也可以用变量存储。
实现方法:
sort快排(默认你打的是从大到小,输入从1开始):快排后,打for循环,从i=2开始,若和a[1]不同,直接输出+return 0;- 变量存储:
maxx = -1,maxx2 = 0;,如果最大的要改,那就用maxx2来存maxx,最后直接输出maxx2就可以了
代码
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 2;
const int N1 = 1e3 + 2;
typedef long long ll;
typedef unsigned long long ull;
signed main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n, maxx = -1, t = 0;
cin >> n;
int a[n + 1];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
for (int i = 0; i < n; i++) {
if (max(maxx, a[i]) == a[i] && maxx != a[i]) {
t = maxx;
maxx = a[i];
}
}
cout << t << '\n';
return 0;
}
[ABC010A] ハンドルネーム
思路
幼儿园的三岁小孩都能做
输入个字符串,
然后输出字符串,最后输出"pp"。
直接收工了。
代码
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 2;
const int N1 = 1e3 + 2;
typedef long long ll;
typedef unsigned long long ull;
signed main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
string a;
cin >> a;
cout << a << "pp";
return 0;
}
[ABC010B] 花占い
题意翻译+简略(只保留做题要用的信息)
给定 \(n\) 朵花的花瓣数量,小高会有两个方案数花瓣:
1:like,2:don't like.
方案 \(1\):三瓣数:“1”,“0”,“1”。
方案 \(2\):两瓣数:“0”,“1”。
现在你需要处理这 \(n\) 朵花,使小高得拿起任意一朵花用任意方案数数到最后一片花瓣得到的结果都是“1”。
借鉴了一下 ivyjiao 的翻译。
思路
这道题可能很难理解,最主要是因为这道题的翻译是机翻,根本看不懂,所以我把题意翻译放前面。
由于\(a[i] ≤ 9\),所以可以打表。
本人写题时把样例推了一遍
代码
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 2;
const int N1 = 1e3 + 2;
typedef long long ll;
typedef unsigned long long ull;
int n, ans, a[10] = {0, 0, 1, 0, 1, 2, 3, 0, 1, 0}, b;//实在推不出来了
signed main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n;
a[8] = 1;
a[2] = 1;
for (int i = 1; i <= n; i++) {
cin >> b;
ans += a[b];
}
cout << ans;
return 0;
}
//5==2 8==1 2==1 1==0==0
//3\4\6\7\9

浙公网安备 33010602011771号