PAT
爱吃胡萝卜的代码兔
天道酬勤
展开
-
解决“寻找有序序列第一个满足某条件的元素的位置”问题的固定模板
代码】解决“寻找有序序列第一个满足某条件的元素的位置”问题的固定模板。原创 2022-07-25 20:05:10 · 179 阅读 · 0 评论 -
1033. To Fill or Not to Fill (25)
#include <iostream>#include <algorithm>#include <vector>using namespace std;const int inf = 99999999;struct station { double price, dis;};bool cmp1(station a, station b) { return a.dis < b.dis;}int main() { double原创 2022-01-06 15:27:35 · 71 阅读 · 0 评论 -
1032. Sharing (25)
#include <cstdio>using namespace std;struct NODE { char key; int next; bool flag;}node[100000];int main() { int s1, s2, n, a, b; scanf("%d%d%d", &s1, &s2, &n); char data; for(int i = 0; i < n; i++) {原创 2020-07-07 19:59:26 · 170 阅读 · 0 评论 -
1031. Hello World for U (20)
#include <iostream>#include <string.h>using namespace std;int main() { char c[81], u[30][30]; memset(u, ' ', sizeof(u)); scanf("%s", c); int n = strlen(c) + 2; int n1 = n / 3, n2 = n / 3 + n % 3, index = 0; for(int i原创 2020-07-07 19:58:48 · 119 阅读 · 0 评论 -
1030. Travel Plan (30)
#include <cstdio>#include <algorithm>#include <vector>using namespace std;int n, m, s, d;int e[510][510], dis[510], cost[510][510];vector<int> pre[510];bool visit[510];const int inf = 99999999;vector<int> path, temppa原创 2020-07-07 19:57:38 · 144 阅读 · 0 评论 -
1029. Median (25)
#include <iostream>const int maxn = 200005;int n, m, a1[maxn], a2[maxn], cnt = 0, i, j, ans;int main() { scanf("%d", &n); for(i = 1; i <= n; i++) scanf("%d", &a1[i]); scanf("%d", &m); for(i = 1; i <= m; i++) scanf原创 2020-07-07 19:56:58 · 128 阅读 · 0 评论 -
1028. List Sorting (25)
#include <iostream>#include <algorithm>#include <string.h>using namespace std;const int maxn = 100001;struct NODE { int no, score; char name[10];}node[maxn];int c;int cmp1(NODE a, NODE b) { if(c == 1) { return原创 2020-07-07 19:56:22 · 112 阅读 · 0 评论 -
1027. Colors in Mars (20)
#include <cstdio>using namespace std;int main() { char c[14] = {"0123456789ABC"}; printf("#"); for(int i = 0; i < 3; i++) { int num; scanf("%d", &num); printf("%c%c", c[num/13], c[num%13]); } retur原创 2020-07-07 19:55:52 · 106 阅读 · 0 评论 -
1026. Table Tennis (30)
#include <iostream>#include <vector>#include <algorithm>#include <cmath>using namespace std;struct person { int arrive, start, time; bool vip;}tempperson;struct tablenode { int end = 8 * 3600, num; bool vip;}原创 2020-07-07 19:55:21 · 123 阅读 · 0 评论 -
1025. PAT Ranking (25)
#include <cstdio>#include <algorithm>#include <vector>using namespace std;struct student { long long int no; int score, finrank, loca, locarank;};bool cmp1(student a, student b) { return a.score != b.score ? a.score >原创 2020-07-07 19:54:52 · 116 阅读 · 0 评论 -
1024. Palindromic Number (25)--C++程序:数字翻转和相加的奇特操作
这道题展示了使用C++编写一个有趣的数字操作程序,它将输入的数字翻转并多次相加,直到达到回文数字或指定的次数。通过字符串操作、循环和条件判断,我们可以实现这一非常特别的任务。下面是完整的代码string s;i < len;carry = 1;int cnt, i;for(i = 0;i原创 2020-07-07 19:54:20 · 8490 阅读 · 1 评论 -
1023. Have Fun with Numbers (20)
#include <cstdio>#include <string.h>using namespace std;int book[10];int main() { char num[22]; scanf("%s", num); int flag = 0, len = strlen(num); for(int i = len - 1; i >= 0; i--) { int temp = num[i] - '0';原创 2020-07-07 19:53:49 · 103 阅读 · 0 评论 -
1022. Digital Library (30)
#include <iostream>#include <map>#include <set>using namespace std;map<string, set<int> > title, author, key, pub, year;void query(map<string, set<int> > &m, string &str) { if(m.find(str) != m.end(原创 2020-07-07 19:53:07 · 104 阅读 · 0 评论 -
1021. Deepest Root (25)
#include <iostream>#include <vector>#include <set>#include <algorithm>using namespace std;int n, maxheight = 0;vector<vector<int>> v;bool visit[10010];set&l...原创 2020-05-01 12:16:37 · 193 阅读 · 0 评论 -
1020. Tree Traversals (25)
#include <iostream>#include <algorithm>#include <vector>using namespace std;struct node { int index, value;};bool cmp(node a, node b) { return a.index < b.index;}v...原创 2020-05-01 12:15:40 · 209 阅读 · 1 评论 -
1019. General Palindromic Number (20)
#include <cstdio>using namespace std;int main() { int a, b; scanf("%d %d", &a, &b); int arr[40], index = 0; while(a != 0) { arr[index++] = a % b; a = a / b; } int flag = 0; ...原创 2020-05-01 12:15:10 · 141 阅读 · 0 评论 -
1018. Public Bike Management (30)
#include <iostream>#include <algorithm>#include <vector>using namespace std;const int inf = 99999999;int cmax, n, sp, m;int minNeed = inf, minBack = inf;int e[510][510], dis[5...原创 2020-05-01 12:14:42 · 161 阅读 · 0 评论 -
1017. Queueing at Bank (25)
#include <iostream>#include <queue>#include <algorithm>using namespace std;const int maxn = 10005;struct person { int come, time;} p[maxn];int cmp(person p1, person p2) { ...原创 2020-05-01 12:11:38 · 139 阅读 · 0 评论 -
1016. Phone Bills (25)
#include <iostream>#include <map>#include <vector>#include <algorithm>using namespace std;struct node { string name; int status, month, time, day, hour, minute;};...原创 2020-05-01 12:09:06 · 133 阅读 · 0 评论 -
1015. Reversible Primes (20)
#include <cstdio>#include <cmath>using namespace std;bool isprime(int n) { if(n <= 1) return false; int sqr = int(sqrt(n * 1.0)); for(int i = 2; i <= sqr; i++) { ...原创 2020-05-01 12:08:35 · 134 阅读 · 1 评论 -
1014. Waiting in Line (30)
#include <iostream>#include <queue>#include <vector>using namespace std;struct node { int poptime, endtime; queue<int> q;};int main() { int n, m, k, q, index ...原创 2020-05-01 12:08:04 · 171 阅读 · 0 评论 -
1013. Battle Over Cities (25)
#include <cstdio>#include <algorithm>using namespace std;int v[1010][1010];bool visit[1010];int n;void dfs(int node) { visit[node] = true; for(int i = 1; i <= n; i++) { ...原创 2020-05-01 12:07:34 · 142 阅读 · 0 评论 -
1012. The Best Rank (25)
#include <cstdio>#include <algorithm>using namespace std;struct node { int id, best; int score[4], rank[4];}stu[2005];int exist[1000000], flag = -1;bool cmp1(node a, node b) ...原创 2020-05-01 12:07:06 · 176 阅读 · 0 评论 -
1011. World Cup Betting (20)
#include <cstdio>using namespace std;int main() { char c[4] = {"WTL"}; double ans = 1.0; for(int i = 0; i < 3; i++) { double maxvalue = 0.0; int maxchar = 0; for(int j = 0; j < ...原创 2020-05-01 12:06:35 · 167 阅读 · 0 评论 -
1010. Radix (25)
#include <iostream>#include <cctype>#include <algorithm>#include <cmath>using namespace std;long long convert(string n, long long radix) { long long sum = 0; int i...原创 2020-05-01 12:06:03 · 137 阅读 · 0 评论 -
1009. Product of Polynomials (25)
#include <iostream>using namespace std;int main() { int n1, n2, a, cnt = 0; scanf("%d", &n1); double b, arr[1001] = {0.0}, ans[2001] = {0.0}; for(int i = 0; i < n1; i++)...原创 2020-05-01 12:05:32 · 128 阅读 · 0 评论 -
1008. Elevator (20)
#include <iostream>using namespace std;int main() { int a, now = 0, sum = 0; cin >> a; while(cin >> a) { if(a > now) sum = sum + 6 * (a - now); ...原创 2020-05-01 12:05:02 · 150 阅读 · 0 评论 -
1007. Maximum Subsequence Sum (25)
#include <iostream>#include <vector>using namespace std;int main() { int n; scanf("%d", &n); vector<int> v(n); int leftindex = 0, rightindex = n - 1, sum = -1,...原创 2020-05-01 12:04:18 · 137 阅读 · 0 评论 -
1006. Sign In and Sign Out (25)
#include <iostream>#include <climits>using namespace std;int main() { int n, minn = INT_MAX, maxn = INT_MIN; scanf("%d", &n); string unlocked, locked; for(int i = 0;...原创 2020-05-01 12:03:38 · 164 阅读 · 0 评论 -
1005. Spell It Right (20)
#include <iostream>using namespace std;int main() { string a; cin >> a; int sum = 0; for (int i = 0; i < a.length(); i++) sum += (a[i] - '0'); string s = t...原创 2020-04-16 19:59:42 · 151 阅读 · 0 评论 -
1004. Counting Leaves (30)
#include <iostream>#include <vector>#include <algorithm>using namespace std;vector<int> v[100];int book[100], maxdepth = -1;void dfs(int index, int depth) { if(v[inde...原创 2020-04-16 19:59:11 · 150 阅读 · 0 评论 -
1003. Emergency (25)
#include <iostream>#include <algorithm>using namespace std;int n, m, c1, c2;int e[510][510], weight[510], dis[510], num[510], w[510];bool visit[510];const int inf = 99999999;int mai...原创 2020-04-16 19:58:41 · 152 阅读 · 0 评论 -
1002. A+B for Polynomials (25)
#include <iostream>using namespace std;int main() { float c[1001] = {0}; int m, n, t; float num; scanf("%d", &m); for (int i = 0; i < m; i++) { scanf("%d%f",...原创 2020-04-16 19:58:10 · 139 阅读 · 0 评论 -
1001. A+B Format (20)
#include <iostream>using namespace std;int main() { int a, b; cin >> a >> b; string s = to_string(a + b); int len = s.length(); for (int i = 0; i < len; i++)...原创 2020-04-16 19:57:40 · 121 阅读 · 0 评论 -
1004 成绩排名 (20)
#include <iostream>using namespace std;int main() { int n, max = -1, min = 101, score; cin >> n; string maxname, minname, maxnum, minnum, name, num; for (int i = 0; i <...原创 2020-04-10 13:52:48 · 78 阅读 · 0 评论 -
1003. 我要通过!(20)
#include <iostream>#include <map>using namespace std;int main() { int n, p = 0, t = 0; string s; cin >> n; for(int i = 0; i < n; i++) { cin >> s;...原创 2020-04-10 13:52:17 · 81 阅读 · 0 评论 -
1001. 害死人不偿命的(3n+1)猜想 (15)
#include <iostream>using namespace std;int main() { int n, count = 0; cin >> n; while (n != 1) { if (n % 2 != 0) n = 3 * n + 1; n = n / 2; count++; ...原创 2020-04-10 13:51:18 · 78 阅读 · 0 评论 -
1002. 写出这个数 (20)
#include <iostream>#include <string>using namespace std;int main() { string s; cin >> s; int sum = 0; string str[10] = {"ling", "yi", "er", "san", "si", "wu", "li...原创 2020-04-10 13:51:46 · 87 阅读 · 0 评论 -
PAT乙级题解目录(新手基础解及待更新迭代解)
编号标题基础解最优解分类备注1001害死人不偿命的(3n+1)猜想C1002C1003C1004C1005C1006C1007C1008C1009C1010C1011C1012C1...原创 2020-04-10 14:08:12 · 396 阅读 · 0 评论