前言
这次天梯赛表现没有达到预期,L1的分没有拿全,L2有2题没考虑完全,总之很愧疚拖了队友后腿。今天先补上L1没拿满分的题。
L1补题
- 前言
- L1-078 吉老师的回归
- 输入样例1
- 输出样例1
- 输入样例2
- 输出样例2
- 思路
- 代码实现
- L1-080 乘法口诀数列
- 输入样例:
- 输出样例:
- 思路
- 代码实现
- 总结:
L1-078 吉老师的回归
输入样例1
5 1
L1-1 is a qiandao problem.
L1-2 is so...easy.
L1-3 is Easy.
L1-4 is qianDao.
Wow, such L1-5, so easy.
输出样例1
L1-4 is qianDao.
输入样例2
5 4
L1-1 is a-qiandao problem.
L1-2 is so easy.
L1-3 is Easy.
L1-4 is qianDao.
Wow, such L1-5, so!!easy.
输出样例2
Wo AK le
思路
用C++ String类的find()函数查找字符串,没找到返回-1.
不了解的小伙伴可以戳这里
代码实现
#include <bits/stdc++.h>
using namespace std;
int main()
{int n, m, cnt = 0, flag = 0;string s;string s1="qiandao", s2="easy";scanf("%d%d",&n,&m);getchar();for(int i=0; i<n; i++){getline(cin,s);if(flag) continue;if(s.find(s1)==-1 && s.find(s2)==-1) cnt ++;if(cnt == m+1){cout << s << endl;flag = 1;}}if(cnt<=m) printf("Wo AK le\n");return 0;
}
L1-080 乘法口诀数列
输入样例:
2 3 10
输出样例:
2 3 6 1 8 6 8 4 8 4
思路
通过观察可以看出,序列中的数满足“先进先出”的思想,因此想到用C++ STL中的队列解决。坑点在于n的范围,如果n=1,那么输出第一个数就结束了,第二个数不用输出(可是我在考场上就没发现这一点啊)。
代码实现
#include <bits/stdc++.h>
using namespace std;
int main()
{int a1, a2, n;scanf("%d%d%d",&a1,&a2,&n);queue <int> q;q.push(a1);q.push(a2);if(n == 1){cout << a1;return 0;}elsecout << a1 << ' ' << a2;int cnt = 2;while(cnt < n){int t1 = q.front();q.pop();int t2 = q.front();int tmp = t1*t2;if(tmp < 10){q.push(tmp);cnt ++;cout << ' ' << tmp;continue;}else{int b1 = tmp/10;int b2 = tmp%10;q.push(b1);cnt ++;cout << ' ' << b1;if(cnt == n) break;q.push(b2);cnt ++;cout << ' ' << b2;}}return 0;
}
总结:
这次天梯赛暴露出我很多问题,比如对DFS的理解不够深入,导致L2病毒那题WA到最后没写出来。这段时间要沉下心来多做题,把之前的基础巩固一下,要提高自己的解题能力;同时也要学一些新的算法,好好理解,多做题。明年天梯再见!(已经立下flag的蒟蒻绝不服输!)