PTA解题实录
EnochChen_
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
L1-019 谁先倒
PTA | 程序设计类实验辅助教学平台两种方法差不多#include <iostream>using namespace std;int main() { int A, B, N, a1, a2, b1, b2; cin >> A >> B >> N; //甲乙酒量 int a = A, b = B; //a和b用来记录A与B何时倒 while (N--) { cin >> a1 >> a2 >>原创 2022-04-21 21:04:37 · 255 阅读 · 0 评论 -
L1-043 阅览室
PTA | 程序设计类实验辅助教学平台#include <iostream>using namespace std;struct node { int startTime; int st;//0表示未被借出,1表示被借出。} book[1001];int getTime(int hour, int minute) { return hour * 60 + minute;}int main() { int id, hour, minute, days; char.原创 2022-04-21 19:58:49 · 439 阅读 · 0 评论 -
L1-059 敲笨钟
PTA | 程序设计类实验辅助教学平台一开始我不明白,怎么把一句话分割输入,并且判断下面是先输入在判断,如果逗号前面时候ong并且.前面也是ong那就是押韵的并且根据空格判断第几个单词#include <iostream>using namespace std;typedef long long ll;const int maxn = 1e5 + 10;string s;int main() { int n; cin >> n; getcha..原创 2022-04-21 17:17:20 · 453 阅读 · 0 评论 -
L1-025 正整数A+B
PTA | 程序设计类实验辅助教学平台按模块写,就不容易写错了#include <iostream>using namespace std;int n1, n2;bool f1 = true, f2 = true, f3 = true, f4 = true;int main() { string a, b; cin >> a; getchar(); getline(cin, b); //b中可能包含空格,所以用getline进行输入 for (int .原创 2022-04-21 16:46:59 · 255 阅读 · 0 评论 -
L1-020 帅到没朋友
#include <iostream>using namespace std;int a[100000];int main() { int n; cin >> n; int x, id; while(n--) { cin >> x; if (x >= 2) { while(x--) { cin >> id; a[id] = 1; } } else cin >> id; }...原创 2022-04-21 16:29:07 · 159 阅读 · 0 评论 -
L1-009 N个数求和
PTA | 程序设计类实验辅助教学平台#include <iostream>using namespace std;int gcd(int a, int b) { return a % b == 0 ? b : gcd(b, a % b);}int a[105] , b[105];int main() { int n, i = 0; scanf("%d", &n); scanf("%d/%d", &a[i], &b[i]); int .原创 2022-04-19 20:49:24 · 214 阅读 · 0 评论 -
L1-002 打印沙漏
PTA | 程序设计类实验辅助教学平台模拟题老是模拟不出来#include <iostream>using namespace std;int main() { int n; char c; cin >> n >> c; int m, i, sum; if (n == 1) cout << c << endl << 0 << endl; else if (n > 1 || n <=原创 2022-04-18 20:42:46 · 253 阅读 · 0 评论 -
L1-046 整除光棍
开long long循环解题,只拿了15分再次读题,题目的答案是光棍数 / x = s我们思考下除法的本质,是不是会发现答案的每一位都是每除一次的商然后剩下的余数*10加上后面一位,也就是说除法实际上只和两位数有关前面被算过了就可以不考虑了,而光棍数我们知道全是1所以后面我们只要补1就行,这样用int就能存下那这样我们先找到比x大的第一个光棍数,然后每次除以x输出商,再把剩下的余数*10+1,不断循环直到余数为0,表示整除完了定义第一个数为1,循环找到比x大且最小的光棍数之后每除一次原创 2022-04-18 20:23:51 · 272 阅读 · 0 评论 -
L1-027 出租
PTA | 程序设计类实验辅助教学平台首先是暴力的解法#include <iostream>#include <vector>using namespace std;vector<int> arr;vector<int> index;int tag[12];int main() { string str; cin >> str; for (int i = 0; i < str.size(); i++) ta原创 2022-04-18 19:52:31 · 254 阅读 · 0 评论 -
L1-034 点赞
PTA | 程序设计类实验辅助教学平台#include <iostream>#include <algorithm>using namespace std;struct node { int b, c;} a[1010];int main() { int n, m, t, k = -10, flag = -10; cin >> n; while (n--) { cin >> m; for (int i = 0; i &l.原创 2022-04-17 21:19:48 · 367 阅读 · 0 评论 -
L1-078 吉老师的回归
PTA | 程序设计类实验辅助教学平台简单题,有一个点一直不过#include <iostream>using namespace std;int main() { int n, k; string s; cin >> n >> k; getchar(); while (n--) { getline(cin, s); if (s.find("qiandao") != -1 || s.find("easy") != -1) con.原创 2022-04-17 20:29:07 · 328 阅读 · 0 评论 -
L1-039 古风排版
PTA | 程序设计类实验辅助教学平台两种方法,第一是先把字符串变成字符数组,第二是把字符串直接输出#include <iostream>#include <cstring>using namespace std;int main() { int n; string s; cin >> n; getchar(); getline(cin, s); char str[2010][2010]; memset(str, ' ', sizeof .原创 2022-04-17 19:54:04 · 241 阅读 · 0 评论 -
L1-080 乘法口诀数列
PTA | 程序设计类实验辅助教学平台需要在引入一个下标j,要不然就会错乱添加位置的下标是i,想乘位置的下标是j另外N尽量开大,至少要大于1534,要不然会出错#include <iostream>using namespace std;const int N = 2010;int a[N];int a1, a2, n;int main() { cin >> a[1] >> a[2] >> n; int j = 3; for原创 2022-04-16 21:04:46 · 307 阅读 · 0 评论 -
L1-011 A-B
PTA | 程序设计类实验辅助教学平台while里面相当于把a里面与b相等的全删除#include <bits/stdc++.h>using namespace std;typedef long long ll;ll pos;string a, b;int main() { getline(cin, a), getline(cin, b); for (ll i = 0; b[i] != '\0'; i++) while ((pos = a.find(b[...原创 2022-04-14 21:40:39 · 307 阅读 · 0 评论 -
L1-069 胎压监测
PTA | 程序设计类实验辅助教学平台记录一下,这道题看网上写的非常简洁#include <iostream>#include <algorithm>using namespace std;int main() { int m[6], cnt = 0, flag; for (int i = 0; i < 6; i++) cin >> m[i]; int maxx = max(max(max(m[0], m[1]), m[2]), m[3原创 2022-04-12 20:01:02 · 541 阅读 · 0 评论 -
L1-050 倒数第N个字符串
PTA | 程序设计类实验辅助教学平台两种方法其实都差不多这个方法用了一些stl#include <bits/stdc++.h>using namespace std;int l, n, sum;string s;int main() { cin >> l >> n; sum = 1; for (int i = 0; i < l; i++) sum *= 26; n = sum - n + 1; ///讲倒数的第几位.原创 2022-04-12 19:32:42 · 295 阅读 · 0 评论 -
L1-018 大笨钟
本题不难,但是有一个点老是过不了,tnnd#include <iostream>using namespace std;int main() { int a, b; scanf("%d:%d", &a, &b); if (a < 12 || (a == 12 && b == 0)) printf("Only %02d:%02d. Too early to Dang.", a, b); else { a -= 12; for原创 2022-04-11 20:57:03 · 159 阅读 · 0 评论 -
L1-058 6翻了
PTA | 程序设计类实验辅助教学平台本题比较简单,唯一要注意的是i要<=s.size,不这样的话如果最后一个是666就输出不出来#include <iostream>using namespace std;int cnt = 0;string s;int main() { getline(cin, s); for (int i = 0; i <= s.size(); i++) { if (s[i] == '6') cnt++; else {.原创 2022-04-11 20:30:24 · 169 阅读 · 0 评论 -
L1-054 福到了
PTA | 程序设计类实验辅助教学平台字符串问题看来还是有很多缺陷,老是写不对这道题先判断对角线是否相等,相等的话进行输出要求的字符#include <iostream>using namespace std;char c;int n, flag = 1;string str[200];int main() { cin >> c >> n; getchar(); for (int i = 0; i < n; i++) getlin原创 2022-04-11 19:44:06 · 250 阅读 · 0 评论 -
L1-048 矩阵A乘以B
PTA | 程序设计类实验辅助教学平台线性代数的矩阵相乘,当时想用一个数组储存,这反而复杂了直接输出,相乘的时候#include <iostream>using namespace std;int a[110][110], b[110][110];int m, n, x, y;int main() { cin >> m >> n; for (int i = 0; i < m; i++) for (int j = 0; j < .原创 2022-04-11 18:55:00 · 272 阅读 · 0 评论 -
L1-030 一帮一
PTA | 程序设计类实验辅助教学平台这道题按理说不难,但是没写对,当时越写越复杂这道题本质就是先区分男女,在看按先后输出#include <iostream>#include <map>using namespace std;int n,a[100],p = 0, q = 0,h1=0,h2=0;string s1[100];string s2[100];int main() { cin >> n; for (int i = 0; i原创 2022-04-10 17:06:06 · 191 阅读 · 0 评论 -
L1-033 出生年
PTA | 程序设计类实验辅助教学平台本题涉及到字符串和数字的切换,我在网上看到很多优雅的解法,大家可以进行参考首先用set函数储存#include<iostream>#include<set>using namespace std;int main(){ int y,n; cin>>y>>n; for(int i=y;i<=3012;i++) { set<int> s;原创 2022-04-10 16:54:27 · 144 阅读 · 0 评论
分享