![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
PAT
Erin2333
这个作者很懒,什么都没留下…
展开
-
1151 LCA in a Binary Tree
没怎么写过树,欠的还是要还的。 目前看了题解是两种做法,一种是直接找,另一种是先建树再LCA(LCA用的裸查找)。 直接查找 a和b的最近公共祖先一定在中序遍历a的位置和中序遍历b的位置之间,而a和b的公共祖先一定在先序遍历中a和b的位置之前。在先序遍历中从0开始查找,找到的第一个中序遍历位置位于a和b之间的就是最近公共祖先。 #include <iostream> #include <algorithm> #include <stdio.h> #include <原创 2021-09-06 21:22:51 · 186 阅读 · 0 评论 -
PAT 1141 Ranking of Institutions
考察:复杂结构体排序+map的使用 说实话,,我觉得这题有点坑,菜鸡本来没有用map写,结果最后两个测试点过不去,改了map之后,发现要先用double记总分之后再转成int,不然的话最后一个测试点会答案错误。 附上代码: #include <iostream> #include <cctype> #include <algorithm> #include <map> using namespace std; struct node{ string原创 2021-03-12 21:59:21 · 91 阅读 · 0 评论 -
PAT 1019 General Palindromic Number
签到题,进制转换。10进制转P进制。 附代码: #include <iostream> #include <vector> using namespace std; int main(){ int n, b, num = 0; scanf("%d %d", &n, &b); int z[40]; do{ z[num ++] = n%b; n = n/b; }while(n != 0);原创 2021-03-12 19:08:50 · 75 阅读 · 0 评论 -
PAT 1027 Colors in Mars
进制转换签到题,10进制转13进制。 虽然是签到题,但我还是写麻烦了。 先附上自己的代码: #include <iostream> using namespace std; char ABC(int x){ if(x % 13 == 10) return 'A'; else if(x % 13 == 11) return 'B'; else if(x % 13 == 12) return 'C'; else return (x%13)+'0'; } void dec_13(int原创 2021-03-12 16:06:24 · 92 阅读 · 0 评论 -
PAT 1154 Vertex Coloring
图的遍历 #include <iostream> #include <vector> #include <set> using namespace std; struct node{ int v1; int v2; }; vector<node> edges(10010); vector<int> vertex(10010); int n, m, k; bool issame(){ for(int i = 0; i &原创 2021-03-12 16:01:51 · 80 阅读 · 0 评论 -
PAT 1071 Speech Patterns
利用map进行字符串处理。 附第一次写的代码 #include <bits/stdc++.h> using namespace std; bool check(char ch){ if(ch >= 'a' && ch <= 'z') return 1; if(ch >= 'A' && ch <= 'Z') return 1; if(ch >= '0' && ch <= '9') retu原创 2021-03-10 15:52:22 · 76 阅读 · 0 评论 -
PAT 1152 Google Recruitment
签到题,但是需要细心一点。 题目说如果质数是0023要输出0023,所以要么输出的时候记得把0补齐。 附上代码 #include <bits/stdc++.h> char num[1010]; bool isPrime(int n){ for(int i = 2; i < sqrt(n); i ++){ if(n % i == 0) return 0; } return 1; } int main(){ int l, k; s原创 2021-03-09 16:50:13 · 103 阅读 · 1 评论 -
PAT 1153 Decode Registration Card of PAT
写了一天半,终于AC了…… //菜鸡养成计划 附上代码: #include<iostream> #include<stdlib.h> #include<stdio.h> #include<algorithm> using namespace std; struct node{ string card; int score; }; struct node2{ int id = 0; int val = 0; }; bool原创 2021-03-09 16:46:27 · 107 阅读 · 0 评论