提交 987907e1 编写于 作者: 每日一练社区's avatar 每日一练社区

add 28 exercises

上级 da282d4a
{
"node_id": "algorithm-13d46f0dd9654171b165f27130012263",
"keywords": [
"蓝桥杯",
"k倍区间"
],
"children": [],
"export": []
}
\ No newline at end of file
#### 问题描述
给定一个长度为N的数列,$A_1, A_2, … A_N,$如果其中一段连续的子序列$A_i, A_{i+1}, … A_j(i <= j)$之和是K的倍数,我们就称这个区间[i, j]是K倍区间。
你能求出数列中总共有多少个K倍区间吗?
#### 输入格式
第一行包含两个整数N和K。(1 <= N, K <= 100000)
以下N行每行包含一个整数$A_i$。(1 <= $A_i$ <= 100000)
#### 输出格式
输出一个整数,代表K倍区间的数目。
#### 样例输入
```
5 2
1
2
3
4
5
```
#### 样例输出
```
6
```
\ No newline at end of file
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long n, k, ans = 0, son[100000], sum[100000], b[100000] = {0};
cin >> n >> k;
for (int i = 0; i < n; i++)
{
cin >> son[i];
if (i != 0)
sum[i] = (sum[i - 1] + son[i]) % k;
else
sum[i] = son[i] % k;
b[sum[i]]++;
ans += b[sum[i]] - 1;
if (sum[i] == 0)
ans++;
}
cout << ans;
return 0;
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "d5ad2458a40a46daaf75bbb9291e6d4b"
}
\ No newline at end of file
# k倍区间
**问题描述**
给定一个长度为N的数列,$A_1, A_2, … A_N,$如果其中一段连续的子序列$A_i, A_{i+1}, … A_j(i <= j)$之和是K的倍数,我们就称这个区间[i, j]是K倍区间。
你能求出数列中总共有多少个K倍区间吗?
**输入格式**
第一行包含两个整数N和K。(1 <= N, K <= 100000)
以下N行每行包含一个整数$A_i$。(1 <= $A_i$ <= 100000)
**输出格式**
输出一个整数,代表K倍区间的数目。
**样例输入**
```
5 2
1
2
3
4
5
```
**样例输出**
```
6
```
以下程序实现了该功能,请你补全空白处代码:
```cpp
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long n, k, ans = 0, son[100000], sum[100000], b[100000] = {0};
cin >> n >> k;
for (int i = 0; i < n; i++)
{
cin >> son[i];
if (i != 0)
__________________
else
sum[i] = son[i] % k;
b[sum[i]]++;
ans += b[sum[i]] - 1;
if (sum[i] == 0)
ans++;
}
cout << ans;
return 0;
}
```
## aop
### before
```cpp
```
### after
```cpp
```
## 答案
```cpp
sum[i] = (sum[i - 1] + son[i]) % k;
```
## 选项
### A
```cpp
sum[i] = (sum[i] + son[i]) % k;
```
### B
```cpp
sum[i] = (sum[i - 1] + son[i]) % k - 1;
```
### C
```cpp
sum[i] = (sum[i - 1] + son[i - 1]) % k;
```
{
"node_id": "algorithm-aa21244fb1374002acf29ed59bee7978",
"keywords": [
"蓝桥杯",
"纸牌三角形"
],
"children": [],
"export": []
}
\ No newline at end of file
A,2,3,4,5,6,7,8,9 共9张纸牌排成一个正三角形(A按1计算)。要求每个边的和相等。
下面就是一种排法
```
A
9 6
4 8
3 7 5 2
```
这样的排法可能会有很多。
如果考虑旋转、镜像后相同的算同一种,一共有多少种不同的排法呢?
\ No newline at end of file
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
int a[9] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
int res = 0;
do
{
int x1 = a[0] + a[1] + a[2] + a[3];
int x2 = a[3] + a[4] + a[5] + a[6];
int x3 = a[6] + a[7] + a[8] + a[0];
if (x1 == x2 && x2 == x3)
{
res++;
}
} while (next_permutation(a, a + 9)); //全排列
cout << res / 3 / 2 << endl; //翻转除以3,镜像除以2
return 0;
}
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "d0cf3c7a3d9d4f5183383e01522aaba3"
}
\ No newline at end of file
# 纸牌三角形
A,2,3,4,5,6,7,8,9 共9张纸牌排成一个正三角形(A按1计算)。要求每个边的和相等。
下面就是一种排法
```
A
9 6
4 8
3 7 5 2
```
这样的排法可能会有很多。
如果考虑旋转、镜像后相同的算同一种,一共有多少种不同的排法呢?
## aop
### before
```cpp
```
### after
```cpp
```
## 答案
```cpp
144
```
## 选项
### A
```cpp
124
```
### B
```cpp
128
```
### C
```cpp
132
```
{
"node_id": "algorithm-6e714b19660c43b6a68d1b01070c3273",
"keywords": [
"蓝桥杯",
"交换瓶子"
],
"children": [],
"export": []
}
\ No newline at end of file
有N个瓶子,编号 1 ~ N,放在架子上。
比如有5个瓶子:
2 1 3 5 4
要求每次拿起2个瓶子,交换它们的位置。
经过若干次后,使得瓶子的序号为:
1 2 3 4 5
对于这么简单的情况,显然,至少需要交换2次就可以复位。
如果瓶子更多呢?你可以通过编程来解决。
输入格式为两行:
第一行: 一个正整数N(N<10000), 表示瓶子的数目
第二行:N个正整数,用空格分开,表示瓶子目前的排列情况。
输出数据为一行一个正整数,表示至少交换多少次,才能完成排序。
例如,输入:
```
5
3 1 2 5 4
```
程序应该输出:
```
3
```
再例如,输入:
```
5
5 4 3 2 1
```
程序应该输出:
```
2
```
#include <iostream>
#include <cstdio>
using namespace std;
const int N = 1e4 + 10;
bool st[N];
int a[N], n, k;
int main()
{
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i]; //瓶子初始序号
for (int i = 1; i <= n; i++) //从每个正确序号出发
if (!st[i]) //如果没有走过
{
k++; //环数量加一
for (int j = i; !st[j]; j = a[j]) //走完这个环 每次变更指向a[j] 即瓶子初始序号的第j个
st[j] = true;
}
cout << n - k; //环最简情况为自指 则最多有n个环 当前有k个环 从K达到n则需要n-k次
return 0;
}
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "eb1d232696874fe88ac354c1fd9af35f"
}
\ No newline at end of file
# 交换瓶子
有N个瓶子,编号 1 ~ N,放在架子上。
比如有5个瓶子:
2 1 3 5 4
要求每次拿起2个瓶子,交换它们的位置。
经过若干次后,使得瓶子的序号为:
1 2 3 4 5
对于这么简单的情况,显然,至少需要交换2次就可以复位。
如果瓶子更多呢?你可以通过编程来解决。
输入格式为两行:
第一行: 一个正整数N(N<10000), 表示瓶子的数目
第二行:N个正整数,用空格分开,表示瓶子目前的排列情况。
输出数据为一行一个正整数,表示至少交换多少次,才能完成排序。
例如,输入:
```
5
3 1 2 5 4
```
程序应该输出:
```
3
```
再例如,输入:
```
5
5 4 3 2 1
```
程序应该输出:
```
2
```
以下<span style="color:red">错误</span>的一项是?
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
```
### after
```cpp
```
## 答案
```cpp
int search(int i);
int n;
int a[10000] = {0};
int main(void)
{
int index, count, i;
index = count = 0;
scanf("%d", &n);
for (i = 0; i < n; i++)
{
scanf("%d", &a[i]);
}
for (i = 0; i < n; i++)
{
int j = search(i);
if (a[index] != a[j])
{
int t = a[index];
a[index] = a[j];
a[j] = t;
count++;
index++;
}
}
printf("%d", count);
return 0;
}
int search(int i)
{
int index, j, k, min;
min = 99999;
for (j = i; j < n; j++)
{
if (min > a[j])
{
min = a[j];
index = j;
}
}
return index;
}
```
## 选项
### A
```cpp
int main()
{
int n, a[10005];
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
int num = 0;
for (int i = 1; i <= n; i++)
{
while (a[i] != i)
{
swap(a[i], a[a[i]]);
num++;
}
}
cout << num << endl;
return 0;
}
```
### B
```cpp
int main()
{
int n;
cin >> n;
int a[n + 5];
for (int i = 0; i < n; i++)
cin >> a[i];
int min;
int num = 0;
for (int i = 0; i < n; i++)
{
min = i;
for (int j = i + 1; j < n; j++)
{
if (a[min] > a[j])
min = j;
}
if (min != i)
{
num++;
swap(a[i], a[min]);
}
}
cout << num << endl;
return 0;
}
```
### C
```cpp
int main()
{
int n;
int num = 0;
scanf("%d", &n);
int a[n + 5];
for (int i = 0; i < n; i++)
{
scanf("%d", &a[i]);
}
for (int i = 1; i < n; i++)
{
if (a[i - 1] > a[i])
{
swap(a[i - 1], a[i]);
num++;
}
}
if (num == n - 1)
{
num = n / 2;
}
cout << num << endl;
return 0;
}
```
{
"node_id": "algorithm-ef16a8876b2446c0981c5b9cf28f278d",
"keywords": [
"蓝桥杯",
"排它平方数"
],
"children": [],
"export": []
}
\ No newline at end of file
203879 * 203879 = 41566646641
这有什么神奇呢?仔细观察,203879 是个6位数,并且它的每个数位上的数字都是不同的,并且它平方后的所有数位上都不出现组成它自身的数字。
具有这样特点的6位数还有一个,请你找出它!
再归纳一下筛选要求:
1. 6位正整数
2. 每个数位上的数字不同
3. 其平方数的每个数位不含原数字的任何组成数位
#include <bits/stdc++.h>
using namespace std;
int main()
{
for (long long i = 100000; i < 1000000; i++)
{
//i要用longlong,不然相乘会溢出
set<int> s1, s2;
int t1 = i;
while (t1)
{
s1.insert(t1 % 10);
t1 /= 10;
}
long long t2 = i * i;
if (s1.size() == 6)
{
while (t2)
{
s2.insert(t2 % 10);
t2 /= 10;
}
bool flag = 1;
for (auto it : s1)
{
if (s2.find(it) != s2.end())
{
flag = 0;
break;
}
}
if (flag == 1)
cout << i << ' ' << i * i << endl;
}
s1.clear();
s2.clear();
}
return 0;
}
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "75807f45a1224b23adabd23547defe58"
}
\ No newline at end of file
# 排它平方数
203879 * 203879 = 41566646641
这有什么神奇呢?仔细观察,203879 是个6位数,并且它的每个数位上的数字都是不同的,并且它平方后的所有数位上都不出现组成它自身的数字。
具有这样特点的6位数还有一个,请你找出它!
再归纳一下筛选要求:
1. 6位正整数
2. 每个数位上的数字不同
3. 其平方数的每个数位不含原数字的任何组成数位
## aop
### before
```cpp
```
### after
```cpp
```
## 答案
```cpp
639172
```
## 选项
### A
```cpp
629173
```
### B
```cpp
691372
```
### C
```cpp
627193
```
{
"node_id": "algorithm-31b85d9ebb8d4d249586825531c04643",
"keywords": [
"蓝桥杯",
"REPEAT 程序"
],
"children": [],
"export": []
}
\ No newline at end of file
附件 prog.txt 中是一个用某种语言写的程序。附件在本文的末尾。
其中 REPEAT k 表示一个次数为 k 的循环。循环控制的范围由缩进表达,从次行开始连续的缩进比该行多的(前面的空白更长的)为循环包含的内容。
![](https://img-blog.csdnimg.cn/20210320200704647.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM0MDEzMjQ3,size_16,color_FFFFFF,t_70)
该片段中从 A = A + 4 所在的行到 A = A + 8 所在的行都在第一行的循环两次中。
REPEAT 6: 所在的行到 A = A + 7 所在的行都在 REPEAT 5: 循环中。
A = A + 5 实际总共的循环次数是 2 × 5 × 6 = 60 次。
请问该程序执行完毕之后,A 的值是多少?
题目给出的 prog.txt 文件:
```
A = 0
REPEAT 2:
A = A + 4
REPEAT 5:
REPEAT 6:
A = A + 5
A = A + 7
REPEAT 6:
A = A + 7
REPEAT 4:
A = A + 2
A = A + 7
A = A + 2
REPEAT 7:
REPEAT 4:
A = A + 8
A = A + 7
A = A + 4
A = A + 5
A = A + 8
REPEAT 8:
A = A + 5
REPEAT 1:
A = A + 2
REPEAT 7:
A = A + 5
A = A + 5
REPEAT 2:
REPEAT 3:
A = A + 1
A = A + 1
REPEAT 5:
A = A + 1
REPEAT 9:
REPEAT 6:
A = A + 5
A = A + 1
REPEAT 6:
A = A + 2
A = A + 8
A = A + 3
REPEAT 2:
A = A + 5
REPEAT 3:
A = A + 9
REPEAT 1:
A = A + 4
REPEAT 2:
A = A + 9
REPEAT 1:
A = A + 6
A = A + 6
A = A + 4
REPEAT 3:
A = A + 7
A = A + 1
REPEAT 2:
A = A + 3
REPEAT 5:
A = A + 2
A = A + 5
A = A + 2
A = A + 4
A = A + 3
REPEAT 4:
A = A + 4
A = A + 3
A = A + 7
REPEAT 5:
REPEAT 4:
A = A + 5
A = A + 7
REPEAT 5:
A = A + 3
REPEAT 3:
A = A + 3
A = A + 1
A = A + 8
A = A + 2
REPEAT 9:
A = A + 5
REPEAT 1:
A = A + 5
A = A + 2
A = A + 8
A = A + 6
REPEAT 3:
REPEAT 4:
A = A + 9
REPEAT 5:
A = A + 2
A = A + 1
REPEAT 9:
A = A + 9
A = A + 2
REPEAT 1:
A = A + 6
A = A + 8
REPEAT 2:
A = A + 9
A = A + 4
A = A + 7
REPEAT 2:
REPEAT 7:
A = A + 3
A = A + 5
REPEAT 3:
A = A + 5
A = A + 3
A = A + 6
A = A + 4
REPEAT 9:
A = A + 2
A = A + 8
A = A + 2
A = A + 3
REPEAT 2:
REPEAT 8:
A = A + 5
A = A + 1
A = A + 6
A = A + 1
A = A + 2
REPEAT 6:
REPEAT 1:
A = A + 3
REPEAT 1:
A = A + 2
REPEAT 4:
A = A + 7
A = A + 1
A = A + 8
REPEAT 6:
A = A + 5
REPEAT 6:
A = A + 3
REPEAT 2:
A = A + 2
A = A + 9
A = A + 7
REPEAT 9:
A = A + 8
REPEAT 9:
A = A + 8
A = A + 9
A = A + 3
A = A + 2
REPEAT 6:
A = A + 3
REPEAT 9:
A = A + 1
A = A + 9
A = A + 5
REPEAT 2:
A = A + 4
A = A + 9
A = A + 8
REPEAT 5:
A = A + 6
A = A + 9
A = A + 1
REPEAT 1:
A = A + 4
A = A + 2
REPEAT 9:
REPEAT 3:
A = A + 4
REPEAT 7:
A = A + 8
A = A + 3
REPEAT 5:
A = A + 9
REPEAT 8:
A = A + 9
A = A + 8
REPEAT 4:
A = A + 7
A = A + 7
A = A + 3
A = A + 5
REPEAT 6:
A = A + 7
REPEAT 7:
A = A + 2
A = A + 2
A = A + 1
REPEAT 8:
REPEAT 1:
REPEAT 4:
A = A + 6
A = A + 6
A = A + 2
REPEAT 5:
A = A + 4
A = A + 8
A = A + 4
REPEAT 1:
A = A + 5
REPEAT 7:
A = A + 8
REPEAT 6:
A = A + 4
A = A + 4
A = A + 8
REPEAT 4:
A = A + 2
REPEAT 2:
A = A + 4
REPEAT 2:
A = A + 3
REPEAT 1:
A = A + 2
A = A + 8
REPEAT 2:
A = A + 7
REPEAT 8:
A = A + 6
A = A + 1
A = A + 7
REPEAT 8:
A = A + 2
REPEAT 8:
REPEAT 6:
A = A + 1
A = A + 6
REPEAT 2:
A = A + 4
A = A + 1
A = A + 7
A = A + 4
REPEAT 4:
REPEAT 9:
A = A + 2
REPEAT 1:
A = A + 2
A = A + 5
REPEAT 8:
REPEAT 6:
A = A + 3
REPEAT 4:
A = A + 1
A = A + 6
A = A + 1
REPEAT 7:
A = A + 7
REPEAT 7:
A = A + 3
A = A + 9
A = A + 1
A = A + 9
REPEAT 3:
A = A + 5
A = A + 5
A = A + 6
A = A + 2
REPEAT 1:
A = A + 4
REPEAT 2:
A = A + 7
REPEAT 1:
A = A + 7
REPEAT 4:
A = A + 7
A = A + 2
REPEAT 5:
A = A + 9
A = A + 1
A = A + 9
A = A + 5
A = A + 9
REPEAT 5:
A = A + 5
REPEAT 1:
A = A + 6
REPEAT 2:
A = A + 3
A = A + 2
A = A + 6
A = A + 8
A = A + 8
A = A + 7
A = A + 5
A = A + 5
REPEAT 2:
A = A + 1
A = A + 7
A = A + 3
REPEAT 2:
A = A + 7
A = A + 1
A = A + 4
REPEAT 1:
REPEAT 7:
REPEAT 2:
A = A + 3
A = A + 5
A = A + 2
A = A + 6
A = A + 1
A = A + 2
A = A + 4
A = A + 9
REPEAT 1:
A = A + 8
REPEAT 8:
REPEAT 4:
REPEAT 8:
A = A + 4
REPEAT 3:
A = A + 1
A = A + 8
REPEAT 7:
A = A + 8
REPEAT 7:
A = A + 7
A = A + 7
REPEAT 7:
A = A + 6
REPEAT 5:
A = A + 9
A = A + 3
REPEAT 4:
A = A + 5
A = A + 5
A = A + 4
REPEAT 9:
REPEAT 3:
A = A + 4
A = A + 3
A = A + 6
REPEAT 1:
A = A + 3
A = A + 3
A = A + 6
REPEAT 6:
A = A + 7
A = A + 7
A = A + 5
A = A + 5
A = A + 1
A = A + 2
A = A + 6
A = A + 6
REPEAT 9:
A = A + 6
REPEAT 1:
REPEAT 2:
A = A + 4
A = A + 7
REPEAT 3:
A = A + 6
REPEAT 5:
A = A + 3
A = A + 6
REPEAT 9:
A = A + 3
A = A + 6
REPEAT 5:
A = A + 8
A = A + 8
REPEAT 3:
A = A + 7
A = A + 9
A = A + 8
A = A + 3
A = A + 3
A = A + 9
REPEAT 6:
A = A + 9
A = A + 1
REPEAT 4:
REPEAT 1:
A = A + 7
REPEAT 9:
A = A + 2
A = A + 9
A = A + 1
A = A + 2
A = A + 8
A = A + 7
A = A + 9
A = A + 6
REPEAT 4:
REPEAT 2:
A = A + 3
REPEAT 3:
A = A + 4
A = A + 4
REPEAT 6:
A = A + 6
A = A + 1
A = A + 5
A = A + 8
REPEAT 2:
A = A + 6
REPEAT 1:
REPEAT 2:
A = A + 2
REPEAT 3:
A = A + 1
REPEAT 1:
A = A + 8
A = A + 7
A = A + 4
A = A + 2
A = A + 8
A = A + 4
REPEAT 5:
REPEAT 6:
A = A + 8
REPEAT 9:
A = A + 5
A = A + 5
REPEAT 5:
A = A + 5
REPEAT 3:
REPEAT 5:
A = A + 4
REPEAT 4:
A = A + 6
A = A + 3
REPEAT 7:
A = A + 3
A = A + 3
A = A + 1
A = A + 7
A = A + 7
A = A + 6
A = A + 5
A = A + 5
A = A + 6
REPEAT 1:
A = A + 9
A = A + 3
REPEAT 1:
REPEAT 1:
A = A + 1
REPEAT 8:
A = A + 5
REPEAT 8:
A = A + 6
REPEAT 4:
A = A + 9
A = A + 4
REPEAT 2:
A = A + 3
A = A + 7
REPEAT 5:
A = A + 7
A = A + 5
A = A + 8
A = A + 7
A = A + 8
A = A + 5
REPEAT 2:
A = A + 5
A = A + 7
A = A + 8
A = A + 5
A = A + 9
REPEAT 2:
REPEAT 6:
A = A + 9
A = A + 1
A = A + 8
A = A + 7
A = A + 1
A = A + 5
REPEAT 3:
A = A + 3
A = A + 9
A = A + 7
REPEAT 3:
A = A + 9
A = A + 1
REPEAT 6:
A = A + 1
REPEAT 9:
REPEAT 7:
A = A + 3
REPEAT 5:
A = A + 5
A = A + 8
A = A + 8
A = A + 1
A = A + 2
REPEAT 4:
A = A + 6
REPEAT 3:
A = A + 3
A = A + 7
REPEAT 8:
REPEAT 1:
A = A + 7
A = A + 8
A = A + 3
A = A + 1
A = A + 2
A = A + 4
A = A + 7
REPEAT 1:
REPEAT 1:
REPEAT 1:
A = A + 4
A = A + 6
REPEAT 1:
A = A + 3
A = A + 9
A = A + 6
REPEAT 9:
A = A + 1
A = A + 6
REPEAT 5:
A = A + 3
A = A + 9
A = A + 5
A = A + 5
A = A + 7
A = A + 2
REPEAT 2:
A = A + 7
A = A + 7
REPEAT 7:
REPEAT 4:
A = A + 6
A = A + 8
REPEAT 6:
A = A + 6
REPEAT 2:
A = A + 1
A = A + 7
A = A + 6
A = A + 7
REPEAT 4:
REPEAT 7:
A = A + 1
REPEAT 2:
A = A + 2
A = A + 5
A = A + 8
A = A + 2
A = A + 1
A = A + 4
REPEAT 8:
A = A + 5
A = A + 6
REPEAT 7:
REPEAT 6:
REPEAT 9:
A = A + 7
A = A + 8
REPEAT 4:
A = A + 6
A = A + 4
A = A + 3
A = A + 6
REPEAT 9:
A = A + 3
REPEAT 9:
A = A + 2
A = A + 7
A = A + 5
A = A + 2
REPEAT 7:
REPEAT 8:
REPEAT 6:
A = A + 4
A = A + 9
A = A + 5
A = A + 3
A = A + 9
REPEAT 4:
REPEAT 1:
A = A + 6
A = A + 8
REPEAT 1:
A = A + 6
A = A + 4
A = A + 6
REPEAT 3:
A = A + 7
REPEAT 3:
A = A + 4
A = A + 4
A = A + 2
A = A + 3
A = A + 7
REPEAT 5:
A = A + 6
A = A + 5
REPEAT 1:
REPEAT 8:
A = A + 5
REPEAT 3:
A = A + 6
REPEAT 9:
A = A + 4
A = A + 3
REPEAT 6:
REPEAT 2:
A = A + 1
A = A + 5
A = A + 2
A = A + 2
A = A + 7
REPEAT 4:
A = A + 7
A = A + 9
A = A + 2
REPEAT 8:
A = A + 9
REPEAT 9:
REPEAT 2:
A = A + 3
A = A + 2
A = A + 1
A = A + 5
REPEAT 9:
A = A + 1
A = A + 3
A = A + 9
REPEAT 7:
A = A + 2
REPEAT 5:
A = A + 9
A = A + 3
REPEAT 2:
A = A + 4
REPEAT 8:
A = A + 9
REPEAT 5:
A = A + 5
A = A + 4
A = A + 2
A = A + 4
REPEAT 6:
A = A + 2
REPEAT 5:
A = A + 7
A = A + 7
A = A + 8
A = A + 3
REPEAT 8:
A = A + 2
A = A + 5
REPEAT 1:
A = A + 8
A = A + 5
A = A + 1
A = A + 1
A = A + 5
REPEAT 2:
A = A + 6
REPEAT 6:
A = A + 9
A = A + 2
A = A + 5
REPEAT 4:
A = A + 7
A = A + 1
REPEAT 6:
A = A + 8
A = A + 4
REPEAT 3:
REPEAT 2:
A = A + 1
A = A + 5
REPEAT 2:
A = A + 7
REPEAT 9:
A = A + 6
A = A + 8
A = A + 9
A = A + 5
REPEAT 9:
REPEAT 3:
A = A + 7
A = A + 7
A = A + 9
A = A + 7
REPEAT 5:
A = A + 7
A = A + 2
A = A + 1
A = A + 8
A = A + 3
A = A + 5
A = A + 1
REPEAT 8:
A = A + 4
A = A + 2
A = A + 2
A = A + 8
REPEAT 4:
REPEAT 4:
A = A + 8
REPEAT 7:
A = A + 5
A = A + 2
REPEAT 2:
A = A + 6
REPEAT 4:
A = A + 8
A = A + 6
A = A + 1
A = A + 3
A = A + 2
A = A + 7
A = A + 4
REPEAT 8:
A = A + 2
A = A + 4
REPEAT 5:
REPEAT 3:
REPEAT 6:
A = A + 8
A = A + 1
A = A + 6
A = A + 5
A = A + 9
REPEAT 8:
A = A + 7
REPEAT 6:
A = A + 4
A = A + 5
REPEAT 3:
A = A + 1
REPEAT 1:
REPEAT 5:
A = A + 6
A = A + 2
REPEAT 9:
REPEAT 5:
A = A + 9
A = A + 3
REPEAT 9:
A = A + 9
A = A + 8
REPEAT 8:
REPEAT 5:
A = A + 9
A = A + 4
REPEAT 9:
A = A + 3
A = A + 4
A = A + 5
REPEAT 9:
REPEAT 7:
A = A + 5
REPEAT 3:
A = A + 7
REPEAT 9:
REPEAT 6:
A = A + 4
A = A + 6
REPEAT 5:
REPEAT 6:
A = A + 5
A = A + 3
A = A + 3
A = A + 3
A = A + 5
REPEAT 7:
A = A + 5
REPEAT 2:
A = A + 5
A = A + 6
REPEAT 2:
A = A + 2
A = A + 5
A = A + 3
A = A + 5
A = A + 5
REPEAT 4:
A = A + 2
A = A + 1
REPEAT 9:
A = A + 9
A = A + 5
A = A + 6
A = A + 2
A = A + 2
A = A + 5
REPEAT 9:
A = A + 5
A = A + 4
REPEAT 4:
REPEAT 4:
A = A + 1
A = A + 2
REPEAT 6:
A = A + 9
A = A + 3
REPEAT 2:
A = A + 5
A = A + 1
A = A + 1
A = A + 3
A = A + 8
REPEAT 7:
A = A + 4
REPEAT 6:
A = A + 9
REPEAT 5:
A = A + 9
A = A + 8
A = A + 3
A = A + 9
A = A + 4
A = A + 6
REPEAT 7:
A = A + 9
REPEAT 9:
A = A + 4
A = A + 9
A = A + 1
A = A + 3
REPEAT 5:
REPEAT 1:
A = A + 4
A = A + 4
REPEAT 8:
A = A + 9
A = A + 6
A = A + 2
REPEAT 3:
A = A + 4
A = A + 4
REPEAT 3:
A = A + 5
A = A + 2
A = A + 8
A = A + 3
A = A + 6
A = A + 4
A = A + 9
A = A + 1
A = A + 9
A = A + 5
A = A + 3
REPEAT 3:
A = A + 2
A = A + 5
A = A + 8
A = A + 2
A = A + 5
REPEAT 8:
REPEAT 2:
A = A + 6
A = A + 7
A = A + 6
A = A + 9
A = A + 2
REPEAT 2:
A = A + 3
REPEAT 8:
A = A + 7
A = A + 2
A = A + 1
A = A + 4
A = A + 1
A = A + 5
A = A + 2
A = A + 1
REPEAT 1:
A = A + 1
REPEAT 6:
A = A + 4
A = A + 3
A = A + 3
REPEAT 5:
A = A + 3
REPEAT 6:
REPEAT 1:
A = A + 5
A = A + 7
A = A + 7
A = A + 7
REPEAT 5:
A = A + 9
A = A + 7
REPEAT 5:
A = A + 9
A = A + 1
A = A + 9
A = A + 8
REPEAT 1:
A = A + 2
REPEAT 5:
A = A + 8
REPEAT 3:
A = A + 2
A = A + 9
A = A + 6
A = A + 3
REPEAT 5:
REPEAT 6:
A = A + 5
A = A + 5
REPEAT 4:
A = A + 5
A = A + 4
REPEAT 8:
A = A + 9
A = A + 1
REPEAT 8:
A = A + 8
A = A + 1
A = A + 4
REPEAT 6:
A = A + 6
REPEAT 2:
A = A + 3
A = A + 9
A = A + 6
A = A + 9
REPEAT 1:
A = A + 4
REPEAT 3:
A = A + 3
A = A + 4
A = A + 2
A = A + 8
REPEAT 2:
A = A + 4
A = A + 1
REPEAT 9:
A = A + 2
A = A + 9
A = A + 7
REPEAT 7:
REPEAT 7:
REPEAT 5:
A = A + 7
REPEAT 5:
A = A + 1
A = A + 1
REPEAT 5:
A = A + 6
REPEAT 1:
A = A + 4
REPEAT 9:
A = A + 4
A = A + 1
REPEAT 6:
A = A + 8
A = A + 5
REPEAT 1:
A = A + 4
REPEAT 5:
A = A + 8
A = A + 7
A = A + 2
REPEAT 3:
A = A + 3
REPEAT 8:
REPEAT 8:
A = A + 4
A = A + 7
REPEAT 5:
A = A + 1
REPEAT 8:
A = A + 7
A = A + 8
A = A + 4
A = A + 7
A = A + 6
A = A + 9
A = A + 5
REPEAT 3:
A = A + 5
REPEAT 9:
A = A + 1
A = A + 7
REPEAT 1:
A = A + 8
A = A + 4
REPEAT 8:
REPEAT 7:
A = A + 2
REPEAT 4:
A = A + 6
A = A + 6
REPEAT 1:
A = A + 7
A = A + 1
REPEAT 9:
REPEAT 5:
A = A + 6
A = A + 5
REPEAT 7:
A = A + 3
A = A + 6
A = A + 8
REPEAT 2:
A = A + 7
A = A + 1
A = A + 9
REPEAT 3:
REPEAT 3:
A = A + 5
```
\ No newline at end of file
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
char mp[N][N];
int s[N], t[N], top;
int main()
{
FILE *fp;
fp = fopen("prog.txt", "r"); ///文件读操作
char ch;
int tot = 0;
int i = 0;
while ((ch = fgetc(fp)) != EOF) ///一个字符一个字符的读入
{
if (ch == '\n')
{
mp[tot][i] = '\0';
tot++;
i = 0;
continue;
}
mp[tot][i++] = ch;
}
/*
for(int i=0;i<tot;i++)
printf("%s\n",mp[i]);*/
///将txt中的数据已经全部保存在了mp数组中
top = 0;
int p, w = 1, sum = 0;
s[top] = -1, t[top] = -1; ///防止栈空的时候进行出栈操作
for (int i = 0; i < tot; i++)
{
int len = strlen(mp[i]);
p = 0;
while (mp[i][p] == ' ') ///统计缩进
p++;
while (s[top] >= p) ///开始新的循环,上一层的循环不包括
w /= t[top--];
if (mp[i][len - 1] == ':') ///当前是循环语句
{
int num = mp[i][len - 2] - '0';
top++;
w *= num; ///累计循环了几次
s[top] = p, t[top] = num; ///第top层循环语句的缩进量和循环次数
}
else
{
int num = mp[i][len - 1] - '0';
sum += w * num;
}
}
printf("%d\n", sum);
return 0;
}
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "38a8afcec1fc4054b7f35f8577fb6724"
}
\ No newline at end of file
# REPEAT 程序
附件 prog.txt 中是一个用某种语言写的程序。附件在本文的末尾。
其中 REPEAT k 表示一个次数为 k 的循环。循环控制的范围由缩进表达,从次行开始连续的缩进比该行多的(前面的空白更长的)为循环包含的内容。
![](https://img-blog.csdnimg.cn/20210320200704647.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM0MDEzMjQ3,size_16,color_FFFFFF,t_70)
该片段中从 A = A + 4 所在的行到 A = A + 8 所在的行都在第一行的循环两次中。
REPEAT 6: 所在的行到 A = A + 7 所在的行都在 REPEAT 5: 循环中。
A = A + 5 实际总共的循环次数是 2 × 5 × 6 = 60 次。
请问该程序执行完毕之后,A 的值是多少?
题目给出的 prog.txt 文件:
```
A = 0
REPEAT 2:
A = A + 4
REPEAT 5:
REPEAT 6:
A = A + 5
A = A + 7
REPEAT 6:
A = A + 7
REPEAT 4:
A = A + 2
A = A + 7
A = A + 2
REPEAT 7:
REPEAT 4:
A = A + 8
A = A + 7
A = A + 4
A = A + 5
A = A + 8
REPEAT 8:
A = A + 5
REPEAT 1:
A = A + 2
REPEAT 7:
A = A + 5
A = A + 5
REPEAT 2:
REPEAT 3:
A = A + 1
A = A + 1
REPEAT 5:
A = A + 1
REPEAT 9:
REPEAT 6:
A = A + 5
A = A + 1
REPEAT 6:
A = A + 2
A = A + 8
A = A + 3
REPEAT 2:
A = A + 5
REPEAT 3:
A = A + 9
REPEAT 1:
A = A + 4
REPEAT 2:
A = A + 9
REPEAT 1:
A = A + 6
A = A + 6
A = A + 4
REPEAT 3:
A = A + 7
A = A + 1
REPEAT 2:
A = A + 3
REPEAT 5:
A = A + 2
A = A + 5
A = A + 2
A = A + 4
A = A + 3
REPEAT 4:
A = A + 4
A = A + 3
A = A + 7
REPEAT 5:
REPEAT 4:
A = A + 5
A = A + 7
REPEAT 5:
A = A + 3
REPEAT 3:
A = A + 3
A = A + 1
A = A + 8
A = A + 2
REPEAT 9:
A = A + 5
REPEAT 1:
A = A + 5
A = A + 2
A = A + 8
A = A + 6
REPEAT 3:
REPEAT 4:
A = A + 9
REPEAT 5:
A = A + 2
A = A + 1
REPEAT 9:
A = A + 9
A = A + 2
REPEAT 1:
A = A + 6
A = A + 8
REPEAT 2:
A = A + 9
A = A + 4
A = A + 7
REPEAT 2:
REPEAT 7:
A = A + 3
A = A + 5
REPEAT 3:
A = A + 5
A = A + 3
A = A + 6
A = A + 4
REPEAT 9:
A = A + 2
A = A + 8
A = A + 2
A = A + 3
REPEAT 2:
REPEAT 8:
A = A + 5
A = A + 1
A = A + 6
A = A + 1
A = A + 2
REPEAT 6:
REPEAT 1:
A = A + 3
REPEAT 1:
A = A + 2
REPEAT 4:
A = A + 7
A = A + 1
A = A + 8
REPEAT 6:
A = A + 5
REPEAT 6:
A = A + 3
REPEAT 2:
A = A + 2
A = A + 9
A = A + 7
REPEAT 9:
A = A + 8
REPEAT 9:
A = A + 8
A = A + 9
A = A + 3
A = A + 2
REPEAT 6:
A = A + 3
REPEAT 9:
A = A + 1
A = A + 9
A = A + 5
REPEAT 2:
A = A + 4
A = A + 9
A = A + 8
REPEAT 5:
A = A + 6
A = A + 9
A = A + 1
REPEAT 1:
A = A + 4
A = A + 2
REPEAT 9:
REPEAT 3:
A = A + 4
REPEAT 7:
A = A + 8
A = A + 3
REPEAT 5:
A = A + 9
REPEAT 8:
A = A + 9
A = A + 8
REPEAT 4:
A = A + 7
A = A + 7
A = A + 3
A = A + 5
REPEAT 6:
A = A + 7
REPEAT 7:
A = A + 2
A = A + 2
A = A + 1
REPEAT 8:
REPEAT 1:
REPEAT 4:
A = A + 6
A = A + 6
A = A + 2
REPEAT 5:
A = A + 4
A = A + 8
A = A + 4
REPEAT 1:
A = A + 5
REPEAT 7:
A = A + 8
REPEAT 6:
A = A + 4
A = A + 4
A = A + 8
REPEAT 4:
A = A + 2
REPEAT 2:
A = A + 4
REPEAT 2:
A = A + 3
REPEAT 1:
A = A + 2
A = A + 8
REPEAT 2:
A = A + 7
REPEAT 8:
A = A + 6
A = A + 1
A = A + 7
REPEAT 8:
A = A + 2
REPEAT 8:
REPEAT 6:
A = A + 1
A = A + 6
REPEAT 2:
A = A + 4
A = A + 1
A = A + 7
A = A + 4
REPEAT 4:
REPEAT 9:
A = A + 2
REPEAT 1:
A = A + 2
A = A + 5
REPEAT 8:
REPEAT 6:
A = A + 3
REPEAT 4:
A = A + 1
A = A + 6
A = A + 1
REPEAT 7:
A = A + 7
REPEAT 7:
A = A + 3
A = A + 9
A = A + 1
A = A + 9
REPEAT 3:
A = A + 5
A = A + 5
A = A + 6
A = A + 2
REPEAT 1:
A = A + 4
REPEAT 2:
A = A + 7
REPEAT 1:
A = A + 7
REPEAT 4:
A = A + 7
A = A + 2
REPEAT 5:
A = A + 9
A = A + 1
A = A + 9
A = A + 5
A = A + 9
REPEAT 5:
A = A + 5
REPEAT 1:
A = A + 6
REPEAT 2:
A = A + 3
A = A + 2
A = A + 6
A = A + 8
A = A + 8
A = A + 7
A = A + 5
A = A + 5
REPEAT 2:
A = A + 1
A = A + 7
A = A + 3
REPEAT 2:
A = A + 7
A = A + 1
A = A + 4
REPEAT 1:
REPEAT 7:
REPEAT 2:
A = A + 3
A = A + 5
A = A + 2
A = A + 6
A = A + 1
A = A + 2
A = A + 4
A = A + 9
REPEAT 1:
A = A + 8
REPEAT 8:
REPEAT 4:
REPEAT 8:
A = A + 4
REPEAT 3:
A = A + 1
A = A + 8
REPEAT 7:
A = A + 8
REPEAT 7:
A = A + 7
A = A + 7
REPEAT 7:
A = A + 6
REPEAT 5:
A = A + 9
A = A + 3
REPEAT 4:
A = A + 5
A = A + 5
A = A + 4
REPEAT 9:
REPEAT 3:
A = A + 4
A = A + 3
A = A + 6
REPEAT 1:
A = A + 3
A = A + 3
A = A + 6
REPEAT 6:
A = A + 7
A = A + 7
A = A + 5
A = A + 5
A = A + 1
A = A + 2
A = A + 6
A = A + 6
REPEAT 9:
A = A + 6
REPEAT 1:
REPEAT 2:
A = A + 4
A = A + 7
REPEAT 3:
A = A + 6
REPEAT 5:
A = A + 3
A = A + 6
REPEAT 9:
A = A + 3
A = A + 6
REPEAT 5:
A = A + 8
A = A + 8
REPEAT 3:
A = A + 7
A = A + 9
A = A + 8
A = A + 3
A = A + 3
A = A + 9
REPEAT 6:
A = A + 9
A = A + 1
REPEAT 4:
REPEAT 1:
A = A + 7
REPEAT 9:
A = A + 2
A = A + 9
A = A + 1
A = A + 2
A = A + 8
A = A + 7
A = A + 9
A = A + 6
REPEAT 4:
REPEAT 2:
A = A + 3
REPEAT 3:
A = A + 4
A = A + 4
REPEAT 6:
A = A + 6
A = A + 1
A = A + 5
A = A + 8
REPEAT 2:
A = A + 6
REPEAT 1:
REPEAT 2:
A = A + 2
REPEAT 3:
A = A + 1
REPEAT 1:
A = A + 8
A = A + 7
A = A + 4
A = A + 2
A = A + 8
A = A + 4
REPEAT 5:
REPEAT 6:
A = A + 8
REPEAT 9:
A = A + 5
A = A + 5
REPEAT 5:
A = A + 5
REPEAT 3:
REPEAT 5:
A = A + 4
REPEAT 4:
A = A + 6
A = A + 3
REPEAT 7:
A = A + 3
A = A + 3
A = A + 1
A = A + 7
A = A + 7
A = A + 6
A = A + 5
A = A + 5
A = A + 6
REPEAT 1:
A = A + 9
A = A + 3
REPEAT 1:
REPEAT 1:
A = A + 1
REPEAT 8:
A = A + 5
REPEAT 8:
A = A + 6
REPEAT 4:
A = A + 9
A = A + 4
REPEAT 2:
A = A + 3
A = A + 7
REPEAT 5:
A = A + 7
A = A + 5
A = A + 8
A = A + 7
A = A + 8
A = A + 5
REPEAT 2:
A = A + 5
A = A + 7
A = A + 8
A = A + 5
A = A + 9
REPEAT 2:
REPEAT 6:
A = A + 9
A = A + 1
A = A + 8
A = A + 7
A = A + 1
A = A + 5
REPEAT 3:
A = A + 3
A = A + 9
A = A + 7
REPEAT 3:
A = A + 9
A = A + 1
REPEAT 6:
A = A + 1
REPEAT 9:
REPEAT 7:
A = A + 3
REPEAT 5:
A = A + 5
A = A + 8
A = A + 8
A = A + 1
A = A + 2
REPEAT 4:
A = A + 6
REPEAT 3:
A = A + 3
A = A + 7
REPEAT 8:
REPEAT 1:
A = A + 7
A = A + 8
A = A + 3
A = A + 1
A = A + 2
A = A + 4
A = A + 7
REPEAT 1:
REPEAT 1:
REPEAT 1:
A = A + 4
A = A + 6
REPEAT 1:
A = A + 3
A = A + 9
A = A + 6
REPEAT 9:
A = A + 1
A = A + 6
REPEAT 5:
A = A + 3
A = A + 9
A = A + 5
A = A + 5
A = A + 7
A = A + 2
REPEAT 2:
A = A + 7
A = A + 7
REPEAT 7:
REPEAT 4:
A = A + 6
A = A + 8
REPEAT 6:
A = A + 6
REPEAT 2:
A = A + 1
A = A + 7
A = A + 6
A = A + 7
REPEAT 4:
REPEAT 7:
A = A + 1
REPEAT 2:
A = A + 2
A = A + 5
A = A + 8
A = A + 2
A = A + 1
A = A + 4
REPEAT 8:
A = A + 5
A = A + 6
REPEAT 7:
REPEAT 6:
REPEAT 9:
A = A + 7
A = A + 8
REPEAT 4:
A = A + 6
A = A + 4
A = A + 3
A = A + 6
REPEAT 9:
A = A + 3
REPEAT 9:
A = A + 2
A = A + 7
A = A + 5
A = A + 2
REPEAT 7:
REPEAT 8:
REPEAT 6:
A = A + 4
A = A + 9
A = A + 5
A = A + 3
A = A + 9
REPEAT 4:
REPEAT 1:
A = A + 6
A = A + 8
REPEAT 1:
A = A + 6
A = A + 4
A = A + 6
REPEAT 3:
A = A + 7
REPEAT 3:
A = A + 4
A = A + 4
A = A + 2
A = A + 3
A = A + 7
REPEAT 5:
A = A + 6
A = A + 5
REPEAT 1:
REPEAT 8:
A = A + 5
REPEAT 3:
A = A + 6
REPEAT 9:
A = A + 4
A = A + 3
REPEAT 6:
REPEAT 2:
A = A + 1
A = A + 5
A = A + 2
A = A + 2
A = A + 7
REPEAT 4:
A = A + 7
A = A + 9
A = A + 2
REPEAT 8:
A = A + 9
REPEAT 9:
REPEAT 2:
A = A + 3
A = A + 2
A = A + 1
A = A + 5
REPEAT 9:
A = A + 1
A = A + 3
A = A + 9
REPEAT 7:
A = A + 2
REPEAT 5:
A = A + 9
A = A + 3
REPEAT 2:
A = A + 4
REPEAT 8:
A = A + 9
REPEAT 5:
A = A + 5
A = A + 4
A = A + 2
A = A + 4
REPEAT 6:
A = A + 2
REPEAT 5:
A = A + 7
A = A + 7
A = A + 8
A = A + 3
REPEAT 8:
A = A + 2
A = A + 5
REPEAT 1:
A = A + 8
A = A + 5
A = A + 1
A = A + 1
A = A + 5
REPEAT 2:
A = A + 6
REPEAT 6:
A = A + 9
A = A + 2
A = A + 5
REPEAT 4:
A = A + 7
A = A + 1
REPEAT 6:
A = A + 8
A = A + 4
REPEAT 3:
REPEAT 2:
A = A + 1
A = A + 5
REPEAT 2:
A = A + 7
REPEAT 9:
A = A + 6
A = A + 8
A = A + 9
A = A + 5
REPEAT 9:
REPEAT 3:
A = A + 7
A = A + 7
A = A + 9
A = A + 7
REPEAT 5:
A = A + 7
A = A + 2
A = A + 1
A = A + 8
A = A + 3
A = A + 5
A = A + 1
REPEAT 8:
A = A + 4
A = A + 2
A = A + 2
A = A + 8
REPEAT 4:
REPEAT 4:
A = A + 8
REPEAT 7:
A = A + 5
A = A + 2
REPEAT 2:
A = A + 6
REPEAT 4:
A = A + 8
A = A + 6
A = A + 1
A = A + 3
A = A + 2
A = A + 7
A = A + 4
REPEAT 8:
A = A + 2
A = A + 4
REPEAT 5:
REPEAT 3:
REPEAT 6:
A = A + 8
A = A + 1
A = A + 6
A = A + 5
A = A + 9
REPEAT 8:
A = A + 7
REPEAT 6:
A = A + 4
A = A + 5
REPEAT 3:
A = A + 1
REPEAT 1:
REPEAT 5:
A = A + 6
A = A + 2
REPEAT 9:
REPEAT 5:
A = A + 9
A = A + 3
REPEAT 9:
A = A + 9
A = A + 8
REPEAT 8:
REPEAT 5:
A = A + 9
A = A + 4
REPEAT 9:
A = A + 3
A = A + 4
A = A + 5
REPEAT 9:
REPEAT 7:
A = A + 5
REPEAT 3:
A = A + 7
REPEAT 9:
REPEAT 6:
A = A + 4
A = A + 6
REPEAT 5:
REPEAT 6:
A = A + 5
A = A + 3
A = A + 3
A = A + 3
A = A + 5
REPEAT 7:
A = A + 5
REPEAT 2:
A = A + 5
A = A + 6
REPEAT 2:
A = A + 2
A = A + 5
A = A + 3
A = A + 5
A = A + 5
REPEAT 4:
A = A + 2
A = A + 1
REPEAT 9:
A = A + 9
A = A + 5
A = A + 6
A = A + 2
A = A + 2
A = A + 5
REPEAT 9:
A = A + 5
A = A + 4
REPEAT 4:
REPEAT 4:
A = A + 1
A = A + 2
REPEAT 6:
A = A + 9
A = A + 3
REPEAT 2:
A = A + 5
A = A + 1
A = A + 1
A = A + 3
A = A + 8
REPEAT 7:
A = A + 4
REPEAT 6:
A = A + 9
REPEAT 5:
A = A + 9
A = A + 8
A = A + 3
A = A + 9
A = A + 4
A = A + 6
REPEAT 7:
A = A + 9
REPEAT 9:
A = A + 4
A = A + 9
A = A + 1
A = A + 3
REPEAT 5:
REPEAT 1:
A = A + 4
A = A + 4
REPEAT 8:
A = A + 9
A = A + 6
A = A + 2
REPEAT 3:
A = A + 4
A = A + 4
REPEAT 3:
A = A + 5
A = A + 2
A = A + 8
A = A + 3
A = A + 6
A = A + 4
A = A + 9
A = A + 1
A = A + 9
A = A + 5
A = A + 3
REPEAT 3:
A = A + 2
A = A + 5
A = A + 8
A = A + 2
A = A + 5
REPEAT 8:
REPEAT 2:
A = A + 6
A = A + 7
A = A + 6
A = A + 9
A = A + 2
REPEAT 2:
A = A + 3
REPEAT 8:
A = A + 7
A = A + 2
A = A + 1
A = A + 4
A = A + 1
A = A + 5
A = A + 2
A = A + 1
REPEAT 1:
A = A + 1
REPEAT 6:
A = A + 4
A = A + 3
A = A + 3
REPEAT 5:
A = A + 3
REPEAT 6:
REPEAT 1:
A = A + 5
A = A + 7
A = A + 7
A = A + 7
REPEAT 5:
A = A + 9
A = A + 7
REPEAT 5:
A = A + 9
A = A + 1
A = A + 9
A = A + 8
REPEAT 1:
A = A + 2
REPEAT 5:
A = A + 8
REPEAT 3:
A = A + 2
A = A + 9
A = A + 6
A = A + 3
REPEAT 5:
REPEAT 6:
A = A + 5
A = A + 5
REPEAT 4:
A = A + 5
A = A + 4
REPEAT 8:
A = A + 9
A = A + 1
REPEAT 8:
A = A + 8
A = A + 1
A = A + 4
REPEAT 6:
A = A + 6
REPEAT 2:
A = A + 3
A = A + 9
A = A + 6
A = A + 9
REPEAT 1:
A = A + 4
REPEAT 3:
A = A + 3
A = A + 4
A = A + 2
A = A + 8
REPEAT 2:
A = A + 4
A = A + 1
REPEAT 9:
A = A + 2
A = A + 9
A = A + 7
REPEAT 7:
REPEAT 7:
REPEAT 5:
A = A + 7
REPEAT 5:
A = A + 1
A = A + 1
REPEAT 5:
A = A + 6
REPEAT 1:
A = A + 4
REPEAT 9:
A = A + 4
A = A + 1
REPEAT 6:
A = A + 8
A = A + 5
REPEAT 1:
A = A + 4
REPEAT 5:
A = A + 8
A = A + 7
A = A + 2
REPEAT 3:
A = A + 3
REPEAT 8:
REPEAT 8:
A = A + 4
A = A + 7
REPEAT 5:
A = A + 1
REPEAT 8:
A = A + 7
A = A + 8
A = A + 4
A = A + 7
A = A + 6
A = A + 9
A = A + 5
REPEAT 3:
A = A + 5
REPEAT 9:
A = A + 1
A = A + 7
REPEAT 1:
A = A + 8
A = A + 4
REPEAT 8:
REPEAT 7:
A = A + 2
REPEAT 4:
A = A + 6
A = A + 6
REPEAT 1:
A = A + 7
A = A + 1
REPEAT 9:
REPEAT 5:
A = A + 6
A = A + 5
REPEAT 7:
A = A + 3
A = A + 6
A = A + 8
REPEAT 2:
A = A + 7
A = A + 1
A = A + 9
REPEAT 3:
REPEAT 3:
A = A + 5
```
## aop
### before
```cpp
```
### after
```cpp
```
## 答案
```cpp
403
```
## 选项
### A
```cpp
400
```
### B
```cpp
401
```
### C
```cpp
402
```
{
"node_id": "algorithm-1a8f872bd3c841808a2bdd47008051f7",
"keywords": [
"蓝桥杯",
"煤球数目"
],
"children": [],
"export": []
}
\ No newline at end of file
有一堆煤球,堆成三角棱锥形。具体:
第一层放1个,
第二层3个(排列成三角形),
第三层6个(排列成三角形),
第四层10个(排列成三角形),
....
如果一共有100层,共有多少个煤球?
\ No newline at end of file
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int main()
{
int i, j;
long long int sum = 0;
for (i = 1; i <= 100; i++)
{
int num = 0;
for (j = 1; j <= i; j++)
num += j;
sum += num;
}
printf("%lld\n", sum);
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "3fca71a7f8294b87bf1af7214c6fc064"
}
\ No newline at end of file
# 煤球数目
有一堆煤球,堆成三角棱锥形。具体:
第一层放1个,
第二层3个(排列成三角形),
第三层6个(排列成三角形),
第四层10个(排列成三角形),
....
如果一共有100层,共有多少个煤球?
## aop
### before
```cpp
```
### after
```cpp
```
## 答案
```cpp
171700
```
## 选项
### A
```cpp
166650
```
### B
```cpp
176851
```
### C
```cpp
182104
```
{
"node_id": "algorithm-b7a24f3dc0894922b58174677d4a1e4a",
"keywords": [
"蓝桥杯",
"门牌制作"
],
"children": [],
"export": []
}
\ No newline at end of file
小蓝要为一条街的住户制作门牌号。
这条街一共有 2020 位住户,门牌号从 1 到 2020 编号。
小蓝制作门牌的方法是先制作 0 到 9 这几个数字字符,最后根据需要将字符粘贴到门牌上,例如门牌 1017 需要依次粘贴字符 1、0、1、7,即需要 1 个字符 0,2 个字符 1,1 个字符 7。
请问要制作所有的 1 到 2020 号门牌,总共需要多少个字符 2?
#include <iostream>
using namespace std;
int ans;
int cal(int n)
{
int sum = 0;
while (n)
{
if (n % 10 == 2)
sum++;
n /= 10;
}
return sum;
}
int main()
{
for (int i = 1; i <= 2020; i++)
{
ans += cal(i);
}
cout << ans << endl;
return 0;
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "94978df2ba4c4b21a6c8666be6e7c735"
}
\ No newline at end of file
# 门牌制作
小蓝要为一条街的住户制作门牌号。
这条街一共有 2020 位住户,门牌号从 1 到 2020 编号。
小蓝制作门牌的方法是先制作 0 到 9 这几个数字字符,最后根据需要将字符粘贴到门牌上,例如门牌 1017 需要依次粘贴字符 1、0、1、7,即需要 1 个字符 0,2 个字符 1,1 个字符 7。
请问要制作所有的 1 到 2020 号门牌,总共需要多少个字符 2?
## aop
### before
```cpp
```
### after
```cpp
```
## 答案
```cpp
624
```
## 选项
### A
```cpp
626
```
### B
```cpp
622
```
### C
```cpp
628
```
{
"node_id": "algorithm-03f5a1063e9948dab7d89631695b4323",
"keywords": [
"蓝桥杯",
"平面切分"
],
"children": [],
"export": []
}
\ No newline at end of file
#### 问题描述
平面上有 N条直线,其中第 i条直线是$ y = A_i*x + B_i$。
请计算这些直线将平面分成了几个部分。
#### 输入格式
第一行包含一个整数N。
以下N行,每行包含两个整数 $A_i, B_i$。
#### 输出格式
一个整数代表答案。
#### 样例输入
```
3
1 1
2 2
3 3
```
#### 样例输出
```
6
```
\ No newline at end of file
#include <bits/stdc++.h>
using namespace std;
long double s[1010][2]; //存储直线的A,B
long long ans;
bool st[1010]; //false表示不是重边
pair<long double, long double> p;
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> s[i][0] >> s[i][1];
set<pair<long double, long double>> points;
for (int j = 0; j < i; j++)
{
if (st[j])
continue; //直线是重边,跳过
if (s[i][0] == s[j][0])
{ //两条直线斜率相等时,判断是平行还是重合
if (s[i][1] == s[j][1])
{
st[i] = true; //待添加直线是重边,退出循环
break;
}
else
continue; //直线平行,不需要计算交点
}
p.first = (s[j][1] - s[i][1]) / (s[i][0] - s[j][0]); //交点的x坐标
p.second = s[i][0] * p.first + s[i][1]; //交点的y坐标
points.insert(p);
}
if (!st[i])
ans += points.size() + 1; //若当前直线不是重边,更新答案
}
cout << ans + 1;
return 0;
}
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "e572003202d0462fa95f635381897624"
}
\ No newline at end of file
# 平面切分
**问题描述**
平面上有 N条直线,其中第 i条直线是$ y = A_i*x + B_i$。
请计算这些直线将平面分成了几个部分。
**输入格式**
第一行包含一个整数N。
以下N行,每行包含两个整数 $A_i, B_i$。
**输出格式**
一个整数代表答案。
**样例输入**
```
3
1 1
2 2
3 3
```
**样例输出**
```
6
```
以下程序实现了这一功能,请你补全空白处的内容:
```cpp
#include <bits/stdc++.h>
using namespace std;
long double s[1010][2];
long long ans;
bool st[1010];
pair<long double, long double> p;
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> s[i][0] >> s[i][1];
set<pair<long double, long double>> points;
for (int j = 0; j < i; j++)
{
if (st[j])
continue;
if (s[i][0] == s[j][0])
{
if (s[i][1] == s[j][1])
{
st[i] = true;
break;
}
else
continue;
}
__________________
p.second = s[i][0] * p.first + s[i][1];
points.insert(p);
}
if (!st[i])
ans += points.size() + 1;
}
cout << ans + 1;
return 0;
}
```
## aop
### before
```cpp
```
### after
```cpp
```
## 答案
```cpp
p.first = (s[j][1] - s[i][1]) / (s[i][0] - s[j][0]);
```
## 选项
### A
```cpp
p.first = (s[j][1] - s[i][1]) / (s[i][1] - s[j][1]);
```
### B
```cpp
p.first = (s[j][0] - s[i][0]) / (s[i][0] - s[j][0]);
```
### C
```cpp
p.first = (s[j][0] - s[i][0]) / (s[i][1] - s[j][1]);
```
{
"node_id": "algorithm-a897b32f6a7244088c8d4a3383ef1902",
"keywords": [
"蓝桥杯",
"消除尾一"
],
"children": [],
"export": []
}
\ No newline at end of file
下面的代码把一个整数的二进制表示的最右边的连续的1全部变成0
如果最后一位是0,则原数字保持不变。
#### 输入:
```
00000000000000000000000001100111
```
#### 输出:
```
00000000000000000000000001100000
```
#### 输入:
```
00000000000000000000000000001100
```
#### 输出:
```
00000000000000000000000000001100
```
\ No newline at end of file
#include <stdio.h>
void f(int x)
{
int i;
for (i = 0; i < 32; i++)
printf("%d", (x >> (31 - i)) & 1);
printf(" ");
x = x & (x + 1);
for (i = 0; i < 32; i++)
printf("%d", (x >> (31 - i)) & 1);
printf("\n");
}
int main()
{
f(103);
f(12);
return 0;
}
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "c2a45eb8e39b4be681fc3d28c1f9bacd"
}
\ No newline at end of file
# 消除尾一
下面的代码把一个整数的二进制表示的最右边的连续的1全部变成0
如果最后一位是0,则原数字保持不变。
**输入:**
```
00000000000000000000000001100111
```
**输出:**
```
00000000000000000000000001100000
```
**输入:**
```
00000000000000000000000000001100
```
**输出:**
```
00000000000000000000000000001100
```
请你填补空白处的内容:
```cpp
#include <stdio.h>
void f(int x)
{
int i;
for (i = 0; i < 32; i++)
printf("%d", (x >> (31 - i)) & 1);
printf(" ");
__________________
for (i = 0; i < 32; i++)
printf("%d", (x >> (31 - i)) & 1);
printf("\n");
}
int main()
{
f(103);
f(12);
return 0;
}
```
## aop
### before
```cpp
```
### after
```cpp
```
## 答案
```cpp
x = x & (x + 1);
```
## 选项
### A
```cpp
x = x & (x - 1);
```
### B
```cpp
x = x && (x - 1);
```
### C
```cpp
x = x && (x + 1);
```
{
"node_id": "algorithm-8e17d142f5aa4b57a697571be7b2fd94",
"keywords": [
"蓝桥杯",
"四平方和"
],
"children": [],
"export": []
}
\ No newline at end of file
四平方和定理,又称为拉格朗日定理:
每个正整数都可以表示为至多4个正整数的平方和。
如果把0包括进去,就正好可以表示为4个数的平方和。
比如:
```
5 = 0^ 2 + 0^ 2 + 1^ 2 + 2^2
7 = 1^ 2 + 1^ 2 + 1^ 2 + 2^2
(^符号表示乘方的意思)
```
对于一个给定的正整数,可能存在多种平方和的表示法。
要求你对4个数排序:
```
0 <= a <= b <= c <= d
```
并对所有的可能表示法按 a,b,c,d 为联合主键升序排列,最后输出第一个表示法
程序输入为一个正整数N (N<5000000)
要求输出4个非负整数,按从小到大排序,中间用空格分开
例如,输入:
```
5
```
则程序应该输出:
```
0 0 1 2
```
再例如,输入:
```
12
```
则程序应该输出:
```
0 2 2 2
```
再例如,输入:
```
773535
```
则程序应该输出:
```
1 1 267 838
```
\ No newline at end of file
#include <iostream>
#include <cstdio>
#include <map>
#include <cmath>
using namespace std;
int N;
map<int, int> cache; //int和int映射,哈希表用于缓存数值
int main()
{
scanf("%d", &N);
for (int c = 0; c * c <= N / 2; c++)
{
for (int d = c; c * c + d * d <= N; d++)
{
if (cache.find(c * c + d * d) == cache.end()) //如果未找到,再去存,已经存在就不需要去存了
cache[c * c + d * d] = c; //查平方数,先要看cache里面有没有,没有说明它不是一个平方数存起来
//有的话通过较小的数映射找到它
}
}
//c*c+d*d要比a*a+d*d要大(至少相同)
for (int a = 0; a * a <= N / 4; a++)
{ //单独看a*a小于等于N/4
for (int b = a; a * a + b * b <= N / 2; b++)
{ //a*a+b*b小于等于N/2
if (cache.find(N - a * a - b * b) != cache.end())
{ //查表,能找到
int c = cache[N - a * a - b * b]; //c就可以知道
int d = int(sqrt(N - a * a - b * b - c * c)); //d开方
printf("%d %d %d %d\n", a, b, c, d);
return 0; //跳出整个主函数
}
}
}
return 0;
}
//整个过程不需要再排序,因为一开始在写代码时,就已经限定了顺序大小,c*c+d*d要比a*a+d*d要大
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "d9e609310d30429bbd1aa87b4b9c6a75"
}
\ No newline at end of file
# 四平方和
四平方和定理,又称为拉格朗日定理:
每个正整数都可以表示为至多4个正整数的平方和。
如果把0包括进去,就正好可以表示为4个数的平方和。
比如:
```
5 = 0^ 2 + 0^ 2 + 1^ 2 + 2^2
7 = 1^ 2 + 1^ 2 + 1^ 2 + 2^2
(^符号表示乘方的意思)
```
对于一个给定的正整数,可能存在多种平方和的表示法。
要求你对4个数排序:
```
0 <= a <= b <= c <= d
```
并对所有的可能表示法按 a,b,c,d 为联合主键升序排列,最后输出第一个表示法
程序输入为一个正整数N (N<5000000)
要求输出4个非负整数,按从小到大排序,中间用空格分开
例如,输入:
```
5
```
则程序应该输出:
```
0 0 1 2
```
再例如,输入:
```
12
```
则程序应该输出:
```
0 2 2 2
```
再例如,输入:
```
773535
```
则程序应该输出:
```
1 1 267 838
```
以下程序实现了这一功能,请你补全空白处内容:
```cpp
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 2500010;
struct Node
{
int s, c, d;
bool operator<(const Node &t) const
{
if (s != t.s)
return s < t.s;
if (c != t.c)
return c < t.c;
return d < t.d;
}
} sum[MAXN];
int n, m;
int main()
{
cin >> n;
for (int c = 0; c * c <= n; c++)
for (int d = c; c * c + d * d <= n; d++)
sum[m++] = {c * c + d * d, c, d};
sort(sum, sum + m);
for (int a = 0; a * a <= n; a++)
{
for (int b = 0; a * a + b * b <= n; b++)
{
int t = n - a * a - b * b;
int l = 0, r = m - 1;
while (l < r)
{
__________________
if (sum[mid].s >= t)
r = mid;
else
l = mid + 1;
}
if (sum[l].s == t)
{
printf("%d %d %d %d", a, b, sum[l].c, sum[l].d);
return 0;
}
}
}
return 0;
}
```
## aop
### before
```cpp
```
### after
```cpp
```
## 答案
```cpp
int mid = l + r >> 1;
```
## 选项
### A
```cpp
int mid = l + (r >> 1);
```
### B
```cpp
int mid = l + r;
```
### C
```cpp
int mid = l + r + 1;
```
{
"node_id": "algorithm-92facd5e0f8d4b6d88589bcddba9f3d7",
"keywords": [
"蓝桥杯",
"完美平方数"
],
"children": [],
"export": []
}
\ No newline at end of file
如果整个整数 X 本身是完全平方数,同时它的每一位数字也都是完全平方数,我们就称 X 是完美平方数。
前几个完美平方数是 0、1、4、9、49、100、144……
即第 1 个完美平方数是 0,第 2 个是 1,第 3 个是 4,……
请你计算第 2020 个完美平方数是多少?
#include <cstdio>
#include <cstring>
struct bign
{
int d[1000];
int len;
bign()
{
memset(d, 0, sizeof(d));
len = 0;
}
} a, b;
bign add(bign &a, bign &b)
{
bign c;
int carry = 0;
for (int i = 0; i < a.len || i < b.len; i++)
{
int temp = a.d[i] + b.d[i] + carry;
c.d[c.len++] = temp % 10;
carry = temp / 10;
}
if (carry)
{
c.d[c.len++] = carry;
}
return c;
}
bign multi(bign &a, int &b)
{
bign c;
int carry = 0;
for (int i = 0; i < a.len; i++)
{
int temp = a.d[i] * b + carry;
c.d[c.len++] = temp % 10;
carry = temp / 10;
}
while (carry)
{
c.d[c.len++] = carry % 10;
carry /= 10;
}
return c;
}
void print(bign &a)
{
for (int i = a.len - 1; i >= 0; i--)
{
printf("%d", a.d[i]);
}
printf("\n");
}
bool vis[10] = {false};
bool judge(bign &c)
{
for (int i = 0; i <= c.len - 1; i++)
{
if (!vis[c.d[i]])
return false;
}
return true;
}
int main()
{
vis[0] = vis[1] = vis[4] = vis[9] = true;
b.d[0] = 1, b.len = 1;
a.d[0] = 0, a.len = 1;
int num = 0;
for (int i = 0; num < 2020; i++)
{
bign c = multi(a, i);
if (judge(c))
{
num++;
printf("%d:", num);
print(c);
}
a = add(a, b);
}
return 0;
}
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "6b9511a8ea9e47c4a4ba3e01fc8f461e"
}
\ No newline at end of file
# 完美平方数
如果整个整数 X 本身是完全平方数,同时它的每一位数字也都是完全平方数,我们就称 X 是完美平方数。
前几个完美平方数是 0、1、4、9、49、100、144……
即第 1 个完美平方数是 0,第 2 个是 1,第 3 个是 4,……
请你计算第 2020 个完美平方数是多少?
## aop
### before
```cpp
```
### after
```cpp
```
## 答案
```cpp
1499441040
```
## 选项
### A
```cpp
1949990009
```
### B
```cpp
914140441
```
### C
```cpp
1101001
```
{
"node_id": "algorithm-be788b02c56e4c8bbc442449c753daf0",
"keywords": [
"蓝桥杯",
"黄金连分数"
],
"children": [],
"export": []
}
\ No newline at end of file
黄金分割数0.61803… 是个无理数,这个常数十分重要,在许多工程问题中会出现。有时需要把这个数字求得很精确。
对于某些精密工程,常数的精度很重要。也许你听说过哈勃太空望远镜,它首次升空后就发现了一处人工加工错误,对那样一个庞然大物,其实只是镜面加工时有比头发丝还细许多倍的一处错误而已,却使它成了“近视眼”!!
言归正传,我们如何求得黄金分割数的尽可能精确的值呢?有许多方法。
比较简单的一种是用连分数:
```
1
黄金数 = ---------------------
1
1 + -----------------
1
1 + -------------
1
1 + ---------
1 + ...
```
这个连分数计算的“层数”越多,它的值越接近黄金分割数。
请你利用这一特性,求出黄金分割数的足够精确值,要求四舍五入到小数点后100位。
小数点后3位的值为:0.618
小数点后4位的值为:0.6180
小数点后5位的值为:0.61803
小数点后7位的值为:0.6180340
(注意尾部的0,不能忽略)
你的任务是:写出精确到小数点后100位精度的黄金分割值。
注意:尾数的四舍五入! 尾数是0也要保留!
显然答案是一个小数,其小数点后有100位数字
#include <iostream>
using namespace std;
typedef long long LL;
void div(LL a, LL b, int end, int begin) //模拟手工除法
{
if (begin > end)
return;
int tmpans = a / b;
cout << tmpans;
div((a % b) * 10, b, end, begin + 1);
}
int main()
{
unsigned long long f[500] = {0, 1};
for (int i = 2; i < 100; i++)
f[i] = f[i - 1] + f[i - 2];
div(f[48], f[49], 100, 0);
return 0;
}
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "4c45c0253bca421fb0d1c8d7fb246832"
}
\ No newline at end of file
# 黄金连分数
黄金分割数0.61803… 是个无理数,这个常数十分重要,在许多工程问题中会出现。有时需要把这个数字求得很精确。
对于某些精密工程,常数的精度很重要。也许你听说过哈勃太空望远镜,它首次升空后就发现了一处人工加工<span style="color:red">错误</span>,对那样一个庞然大物,其实只是镜面加工时有比头发丝还细许多倍的一处<span style="color:red">错误</span>而已,却使它成了“近视眼”!!
言归正传,我们如何求得黄金分割数的尽可能精确的值呢?有许多方法。
比较简单的一种是用连分数:
```
1
黄金数 = ---------------------
1
1 + -----------------
1
1 + -------------
1
1 + ---------
1 + ...
```
这个连分数计算的“层数”越多,它的值越接近黄金分割数。
请你利用这一特性,求出黄金分割数的足够精确值,要求四舍五入到小数点后100位。
小数点后3位的值为:0.618
小数点后4位的值为:0.6180
小数点后5位的值为:0.61803
小数点后7位的值为:0.6180340
(注意尾部的0,不能忽略)
你的任务是:写出精确到小数点后100位精度的黄金分割值。
注意:尾数的四舍五入! 尾数是0也要保留!
显然答案是一个小数,其小数点后有100位数字
## aop
### before
```cpp
```
### after
```cpp
```
## 答案
```cpp
0.6180339887498948482045868343656381177203091798057628621354486227052604628189024497072072041893911375
```
## 选项
### A
```cpp
0.6180339887498948482045868343656389332927878467731611281824609112882717278172075687340936512886003869
```
### B
```cpp
0.6180339887498948482045868343656381177203091798057628621354486227052604628189024496923340122463725713
```
### C
```cpp
0.6180339887498948482045868343656382367107301981874040757690591496236273680999331990382076023866480180
```
{
"node_id": "algorithm-dc6f30bd00214f50b5ba70dcfcb8c35f",
"keywords": [
"蓝桥杯",
"字母阵列"
],
"children": [],
"export": []
}
\ No newline at end of file
仔细寻找,会发现:在下面的8x8的方阵中,隐藏着字母序列:“LANQIAO”。
```
SLANQIAO
ZOEXCCGB
MOAYWKHI
BCCIPLJQ
SLANQIAO
RSFWFNYA
XIFZVWAL
COAIQNAL
```
我们约定: 序列可以水平,垂直,或者是斜向;并且走向不限(实际上就是有一共8种方向)。
上面一共有4个满足要求的串。
下面有一个更大的(100x100)的字母方阵。
你能算出其中隐藏了多少个“LANQIAO”吗?
我就把这些东西放在了txt文件里
```
FOAIQNALWIKEGNICJWAOSXDHTHZPOLGYELORAUHOHCZIERPTOOJUITQJCFNIYYQHSBEABBQZPNGYQTCLSKZFCYWDGOAIADKLSNGJ
GSOZTQKCCSDWGUWAUOZKNILGVNLMCLXQVBJENIHIVLRPVVXXFTHQUXUAVZZOFFJHYLMGTLANQIAOQQILCDCJERJASNCTLYGRMHGF
TSDFYTLVIBHKLJVVJUDMKGJZGNNSTPVLCKTOFMUEUFSVQIAUVHNVFTGBDDARPKYNNCUOYUAZXQJNOEEYKLFRMOEMHUKJTPETHLES
FKVINSLWEVGAGMKVFVIUBMYOIAFHLVNKNTYKTZWVXQWRWIGPENFXYDTKRVPKRTHMGHVYOCLDCKMEKRLGEKBYUCLOLYPAKPFSOREH
KWPUOLOVMOFBIXYACWRDYBINTMPASPCEOKHXQIGBQQMCEOIVULIEOPFSCSIHENAJCVDPJDOIWIIULFDNOZOFVAMCABVGKAKCOZMG
XWMYRTAFGFOCNHLBGNGOXPJSTWLZUNNAGIRETGXFWAQSSJPFTQAXMTQWMZWYVEPQERKSWTSCHSQOOBGXAQTBCHOEGBDVKGWJIFTG
ZWWJEIISPLMXIMGHOOGDRZFTGNDDWDWMNUFWJYJGULPHNUFSAQNNIUVAAFZIAZKFXXNWCEABGJAUMGYEIEFVQXVHHHEDYUITRCQB
XZHDPZQTOBECJVBZLACVXACZEDYOGVAVQRNWEOWGRAQYUEUESTEDQTYJUTEFOOITSHDDZHONJGBRCWNEQLZUTBNQIADKNFIOMWZR
EBFKCVNLURZSNPOLTISRPDTNUMCDGKTYRGIOVEPTUTSBAWQKWWEUWIWHAANUZUADGZEATZOQICWFUJTWNZDBKLQNELWVTBNDLNFH
PESISEATZNCDFRMXBQUKBFTIGYSFCWVHPMSUSDKPSCOMVLDOHYQVFHAJKRDTAVLIMNZBZSMLMRTLRPSLAHXDBASDMWAAYBPYVJZF
SCCWY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KSWFIAKNHMRLNJTKGVNTGLCVPVMBLJANOBCXUGVWBJYSIXZQVAVFWILWFB
QWNLTPMCYHRSKVHXLONRANWKWXUTHYQLIOFKGDBMSWDRCYRKVSAGGRJMWQYQFLMUIGGCLAUQAACTYLPZEOJBHMWRKHCRXGTGRMUP
CPQKJRBLYDNPUGHCRBVYBAIRVCAWLBWVWCMKNBIRKJOUGYQEBQRHDSTWXDIWGRVMLIJFBWHLHCDAAVUDLZSCGQNOUXVUIVIZZZMD
NMHGYPFUUDWKQGTAKKGCDFJFYJFNRZVXDPGZEAMWQVQZODKTXHIYFVKJSSAWVHYCUCZMLLBPXTILDYJQEMWDRUFKISOUVPUDTYPB
FDAQUBXHUJYTAYNWVIJNUSQDTQDEMUAPWXRYUWONTBDZCHZOUEGPMWEZTQWWSHAYOBWVTDIMZYNVNZKUHOFCQKPHJXWNRCGUJEKO
WSDAUGUTVWCVHEMOIRJJGTANUWTSAIXXEVZTBDHPGSRHHVWCDZVZYRJTLONIJVXEATHQXOUKBIGZONFRSZIOGWNTYAJYLQCGEOWY
```
\ No newline at end of file
#include <bits/stdc++.h>
using namespace std;
int main()
{
char a[100][100];
ifstream fin("1.txt"); //我把那些字符放在了1.txt里,读取它
for (int i = 0; i < 100; i++)
{
for (int j = 0; j < 100; j++)
{
fin >> a[i][j];
}
}
fin.close(); //关闭读取文件
int sum, i, j;
for (i = 0; i < 105; i++) //把Q放在前面,分成八个方向分别判断是否成为LANQIAO。
{
for (j = 0; j < 105; j++)
{
if (a[i][j] == 'Q' && j >= 3 && j < 97)
{
if (a[i][j - 3] == 'L' && a[i][j - 2] == 'A' && a[i][j - 1] == 'N' && a[i][j + 1] == 'I' && a[i][j + 2] == 'A' && a[i][j + 3] == 'O')
sum++;
if (a[i][j - 3] == 'O' && a[i][j - 2] == 'A' && a[i][j - 1] == 'I' && a[i][j + 1] == 'N' && a[i][j + 2] == 'A' && a[i][j + 3] == 'L')
sum++;
}
if (a[i][j] == 'Q' && i >= 3 && i < 97)
{
if (a[i - 3][j] == 'L' && a[i - 2][j] == 'A' && a[i - 1][j] == 'N' && a[i + 1][j] == 'I' && a[i + 2][j] == 'A' && a[i + 3][j] == 'O')
sum++;
if (a[i - 3][j] == 'O' && a[i - 2][j] == 'A' && a[i - 1][j] == 'I' && a[i + 1][j] == 'N' && a[i + 2][j] == 'A' && a[i + 3][j] == 'L')
sum++;
}
if (a[i][j] == 'Q' && i >= 3 && i < 97 && j >= 3 && j < 97)
{
if (a[i - 3][j - 3] == 'L' && a[i - 2][j - 2] == 'A' && a[i - 1][j - 1] == 'N' && a[i + 1][j + 1] == 'I' && a[i + 2][j + 2] == 'A' && a[i + 3][j + 3] == 'O')
sum++;
if (a[i - 3][j - 3] == 'O' && a[i - 2][j - 2] == 'A' && a[i - 1][j - 1] == 'I' && a[i + 1][j + 1] == 'N' && a[i + 2][j + 2] == 'A' && a[i + 3][j + 3] == 'L')
sum++;
if (a[i + 3][j - 3] == 'L' && a[i + 2][j - 2] == 'A' && a[i + 1][j - 1] == 'N' && a[i - 1][j + 1] == 'I' && a[i - 2][j + 2] == 'A' && a[i - 3][j + 3] == 'O')
sum++;
if (a[i + 3][j - 3] == 'O' && a[i + 2][j - 2] == 'A' && a[i + 1][j - 1] == 'I' && a[i - 1][j + 1] == 'N' && a[i - 2][j + 2] == 'A' && a[i - 3][j + 3] == 'L')
sum++;
}
}
}
printf("%d", sum);
}
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f1f09e2a086b4304a9f3df41413c566e"
}
\ No newline at end of file
# 字母阵列
仔细寻找,会发现:在下面的8x8的方阵中,隐藏着字母序列:“LANQIAO”。
```
SLANQIAO
ZOEXCCGB
MOAYWKHI
BCCIPLJQ
SLANQIAO
RSFWFNYA
XIFZVWAL
COAIQNAL
```
我们约定: 序列可以水平,垂直,或者是斜向;并且走向不限(实际上就是有一共8种方向)。
上面一共有4个满足要求的串。
下面有一个更大的(100x100)的字母方阵。
你能算出其中隐藏了多少个“L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ANOBCXUGVWBJYSIXZQVAVFWILWFB
QWNLTPMCYHRSKVHXLONRANWKWXUTHYQLIOFKGDBMSWDRCYRKVSAGGRJMWQYQFLMUIGGCLAUQAACTYLPZEOJBHMWRKHCRXGTGRMUP
CPQKJRBLYDNPUGHCRBVYBAIRVCAWLBWVWCMKNBIRKJOUGYQEBQRHDSTWXDIWGRVMLIJFBWHLHCDAAVUDLZSCGQNOUXVUIVIZZZMD
NMHGYPFUUDWKQGTAKKGCDFJFYJFNRZVXDPGZEAMWQVQZODKTXHIYFVKJSSAWVHYCUCZMLLBPXTILDYJQEMWDRUFKISOUVPUDTYPB
FDAQUBXHUJYTAYNWVIJNUSQDTQDEMUAPWXRYUWONTBDZCHZOUEGPMWEZTQWWSHAYOBWVTDIMZYNVNZKUHOFCQKPHJXWNRCGUJEKO
WSDAUGUTVWCVHEMOIRJJGTANUWTSAIXXEVZTBDHPGSRHHVWCDZVZYRJTLONIJVXEATHQXOUKBIGZONFRSZIOGWNTYAJYLQCGEOWY
```
## aop
### before
```cpp
```
### after
```cpp
```
## 答案
```cpp
41
```
## 选项
### A
```cpp
38
```
### B
```cpp
39
```
### C
```cpp
40
```
{
"node_id": "algorithm-d27bd096aa7a423bac3d435800cc8501",
"keywords": [
"蓝桥杯",
"字符串编码"
],
"children": [],
"export": []
}
\ No newline at end of file
#### 问题描述
小明发明了一种给由全大写字母组成的字符串编码的方法。
对于每一个大写字母,小明将它转换成它在 26 个英文字母中序号,即 A → 1, B → 2, … Z →26。
这样一个字符串就能被转化成一个数字序列:比如 ABCXYZ → 123242526。
现在给定一个转换后的数字序列,小明想还原出原本的字符串。
当然这样的还原有可能存在多个符合条件的字符串。
小明希望找出其中字典序最大的字符串。
#### 输入格式
一个数字序列。
#### 输出格式
一个只包含大写字母的字符串,代表答案
#### 样例输入
```
123242526
```
#### 样例输出
```
LCXYZ
```
#### 数据范围
```
对于 20% 的评测用例,输入的长度不超过 20。
对于所有评测用例,输入的长度不超过 200000。
```
\ No newline at end of file
#include <iostream>
#include <cstring>
using namespace std;
const int N = 200010;
char op[27] = {'0',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
int main()
{
string s;
cin >> s;
string ans;
for (int i = 0; i < s.size(); i++)
{
if (i + 1 < s.size())
{
int t = (s[i] - '0') * 10 + (s[i + 1] - '0');
if (t <= 26)
{
ans += op[t];
i++;
}
else
ans += op[s[i] - '0'];
}
else
ans += op[s[i] - '0'];
}
cout << ans << endl;
return 0;
}
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "eefc0335733a482fa5ef4c6b6747f414"
}
\ No newline at end of file
# 字符串编码
**问题描述**
小明发明了一种给由全大写字母组成的字符串编码的方法。
对于每一个大写字母,小明将它转换成它在 26 个英文字母中序号,即 A → 1, B → 2, … Z →26。
这样一个字符串就能被转化成一个数字序列:比如 ABCXYZ → 123242526。
现在给定一个转换后的数字序列,小明想还原出原本的字符串。
当然这样的还原有可能存在多个符合条件的字符串。
小明希望找出其中字典序最大的字符串。
**输入格式**
一个数字序列。
**输出格式**
一个只包含大写字母的字符串,代表答案
**样例输入**
```
123242526
```
**样例输出**
```
LCXYZ
```
**数据范围**
```
对于 20% 的评测用例,输入的长度不超过 20。
对于所有评测用例,输入的长度不超过 200000。
```
以下程序实现了这一功能,请你补全空白处内容:
```cpp
#include <bits/stdc++.h>
using namespace std;
int main()
{
string in;
string re = "";
cin >> in;
int len = in.length();
in = in + 'Z';
for (int i = 0; i < len;)
{
int temp = int(in[i] - '0') * 10 + int(in[i + 1] - '0');
if (temp > 26)
{
re = re + char(in[i] - '0' + 'A' - 1);
i++;
}
else
{
__________________
}
}
cout << re;
return 0;
}
```
## aop
### before
```cpp
```
### after
```cpp
```
## 答案
```cpp
re = re + char(temp + 'A' - 1);
i += 2;
```
## 选项
### A
```cpp
re = re + char(temp + 'A' - 1);
i += 1;
```
### B
```cpp
re = re + char(temp + 'A');
i += 1;
```
### C
```cpp
re = re + char(temp + 'A');
i += 2;
```
{
"node_id": "algorithm-af235ccf483e404a8ab217aead930d8c",
"keywords": [
"蓝桥杯",
"格子中输出"
],
"children": [],
"export": []
}
\ No newline at end of file
StringInGrid函数会在一个指定大小的格子中打印指定的字符串。 要求字符串在水平、垂直两个方向上都居中。 如果字符串太长,就截断。 如果不能恰好居中,可以稍稍偏左或者偏上一点。
输出:
![](https://img-blog.csdnimg.cn/20200327144609874.png#pic_center)
\ No newline at end of file
#include <stdio.h>
#include <string.h>
void StringInGrid(int width, int height, const char *s)
{
int i, k;
char buf[1000];
strcpy(buf, s);
if (strlen(s) > width - 2)
buf[width - 2] = 0;
printf("+");
for (i = 0; i < width - 2; i++)
printf("-");
printf("+\n");
for (k = 1; k < (height - 1) / 2; k++)
{
printf("|");
for (i = 0; i < width - 2; i++)
printf(" ");
printf("|\n");
}
printf("|");
printf("%*s%s%*s", (width - strlen(buf) - 2) / 2, "", buf, (width - strlen(buf) - 2) / 2, "");
printf("|\n");
for (k = (height - 1) / 2 + 1; k < height - 1; k++)
{
printf("|");
for (i = 0; i < width - 2; i++)
printf(" ");
printf("|\n");
}
printf("+");
for (i = 0; i < width - 2; i++)
printf("-");
printf("+\n");
}
int main()
{
StringInGrid(20, 6, "abcd1234");
return 0;
}
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "9b7ed564233642b4a3be0a822719234e"
}
\ No newline at end of file
# 格子中输出
StringInGrid函数会在一个指定大小的格子中打印指定的字符串。 要求字符串在水平、垂直两个方向上都居中。 如果字符串太长,就截断。 如果不能恰好居中,可以稍稍偏左或者偏上一点。
输出:
![](https://img-blog.csdnimg.cn/20200327144609874.png#pic_center)
以下程序实现了这一功能,请你补全空白处内容:
```cpp
#include <stdio.h>
#include <string.h>
void StringInGrid(int width, int height, const char *s)
{
int i, k;
char buf[1000];
strcpy(buf, s);
if (strlen(s) > width - 2)
buf[width - 2] = 0;
printf("+");
for (i = 0; i < width - 2; i++)
printf("-");
printf("+\n");
for (k = 1; k < (height - 1) / 2; k++)
{
printf("|");
for (i = 0; i < width - 2; i++)
printf(" ");
printf("|\n");
}
printf("|");
printf("%*s%s%*s", __________________;
printf("|\n");
for (k = (height - 1) / 2 + 1; k < height - 1; k++)
{
printf("|");
for (i = 0; i < width - 2; i++)
printf(" ");
printf("|\n");
}
printf("+");
for (i = 0; i < width - 2; i++)
printf("-");
printf("+\n");
}
int main()
{
StringInGrid(20, 6, "abcd1234");
return 0;
}
```
## aop
### before
```cpp
```
### after
```cpp
```
## 答案
```cpp
(width - strlen(buf) - 2) / 2, "", buf, (width - strlen(buf) - 2) / 2, ""
```
## 选项
### A
```cpp
(width - strlen(buf) - 1) / 2, "", buf, (width - strlen(buf) - 1) / 2, ""
```
### B
```cpp
(width - strlen(buf) + 1) / 2, "", buf, (width - strlen(buf) + 1) / 2, ""
```
### C
```cpp
(width - strlen(buf) - 2), "", buf, (width - strlen(buf) - 2), ""
```
{
"node_id": "algorithm-068d044e1db44935ab46bcfc3020fd41",
"keywords": [
"蓝桥杯",
"最大公共子串"
],
"children": [],
"export": []
}
\ No newline at end of file
最大公共子串长度问题就是:
求两个串的所有子串中能够匹配上的最大长度是多少。
比如:“abcdkkk” 和 “baabcdadabc”,
可以找到的最长的公共子串是"abcd",所以最大公共子串长度为4。
下面的程序是采用矩阵法进行求解的,这对串的规模不大的情况还是比较有效的解法。
#include <stdio.h>
#include <string.h>
#define N 256
int f(const char *s1, const char *s2)
{
int a[N][N];
int len1 = strlen(s1);
int len2 = strlen(s2);
int i, j;
memset(a, 0, sizeof(int) * N * N);
int max = 0;
for (i = 1; i <= len1; i++)
{
for (j = 1; j <= len2; j++)
{
if (s1[i - 1] == s2[j - 1])
{
a[i][j] = a[i - 1][j - 1] + 1; //填空
if (a[i][j] > max)
max = a[i][j];
}
}
}
return max;
}
int main()
{
printf("%d\n", f("abcdkkk", "baabcdadabc"));
return 0;
}
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "6be1237b0e294a2f92408c026803ce22"
}
\ No newline at end of file
# 最大公共子串
最大公共子串长度问题就是:
求两个串的所有子串中能够匹配上的最大长度是多少。
比如:“abcdkkk” 和 “baabcdadabc”,
可以找到的最长的公共子串是"abcd",所以最大公共子串长度为4。
下面的程序是采用矩阵法进行求解的,这对串的规模不大的情况还是比较有效的解法。
请你补全空白处的内容:
```cpp
#include <stdio.h>
#include <string.h>
#define N 256
int f(const char *s1, const char *s2)
{
int a[N][N];
int len1 = strlen(s1);
int len2 = strlen(s2);
int i, j;
memset(a, 0, sizeof(int) * N * N);
int max = 0;
for (i = 1; i <= len1; i++)
{
for (j = 1; j <= len2; j++)
{
if (s1[i - 1] == s2[j - 1])
{
__________________
if (a[i][j] > max)
max = a[i][j];
}
}
}
return max;
}
int main()
{
printf("%d\n", f("abcdkkk", "baabcdadabc"));
return 0;
}
```
## aop
### before
```cpp
```
### after
```cpp
```
## 答案
```cpp
a[i][j] = a[i - 1][j - 1] + 1;
```
## 选项
### A
```cpp
a[i][j] = a[i - 1][j - 1];
```
### B
```cpp
a[i][j] = a[i - 1][j] + 1;
```
### C
```cpp
a[i][j] = a[i][j - 1] + 1;
```
{
"node_id": "algorithm-260e61bb6bbf44e1a55b0a439e14f7ee",
"keywords": [
"蓝桥杯",
"振兴中华"
],
"children": [],
"export": []
}
\ No newline at end of file
小明参加了学校的趣味运动会,其中的一个项目是:跳格子。
地上画着一些格子,每个格子里写一个字,如下所示:
```
从我做起振
我做起振兴
做起振兴中
起振兴中华
```
![](https://img-blog.csdn.net/20180327194316347)
比赛时,先站在左上角的写着“从”字的格子里,可以横向或纵向跳到相邻的格子里,但不能跳到对角的格子或其它位置。一直要跳到“华”字结束。
要求跳过的路线刚好构成“从我做起振兴中华”这句话。
请你帮助小明算一算他一共有多少种可能的跳跃路线呢?
\ No newline at end of file
#include <bits/stdc++.h>
using namespace std;
int a[4][5];
int sum;
void dfs(int row, int col, int index)
{
if (a[row][col] == index && index == 7)
sum++;
else
{
if (row + 1 < 4)
dfs(row + 1, col, index + 1);
if (col + 1 < 5)
dfs(row, col + 1, index + 1);
}
}
int main()
{
int row, col;
for (row = 0; row < 4; row++)
for (col = 0; col < 5; col++)
a[row][col] = row + col;
dfs(0, 0, 0);
cout << sum << endl;
return 0;
}
\ No newline at end of file
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册