PAT甲级
杨戬没有你我怎么活
喜欢的人是杨戬!
展开
-
PAT 甲级 1027 Colors in Mars
People in Mars represent the colors in their computers in a similar way as the Earth people. That is, a color is represented by a 6-digit number, where the first 2 digits are for Red, the middle 2 digits for Green, and the last 2 digits for Blue. The only原创 2020-11-13 19:21:52 · 77 阅读 · 0 评论 -
PAT_A Radix
这道题难点就是二分法,以及注意溢出#include <iostream>#include "bits/stdc++.h"#define ll long longusing namespace std;ll change(string num,ll raddix){ ll sum = 0; ll temp = 1; for(int i = num.size()-1;i>=0;i--) { if(isalpha(num[i]))原创 2020-09-15 20:11:43 · 76 阅读 · 0 评论 -
PAT_A 1007 Maximum Subsequence Sum
题解:这道题有坑,坑点就是如果一系列全是负数的话,那么sum = 0,输出第一个和最后一个数。除去这个,就是一道很标准的找最大和序列的题目。如果你今天亏钱了,但是还有总资产,那么还有希望,但是如果总资产没有了还欠钱了(tmp<0),那么你就最好从零开始。code:#include <iostream>#include <bits/stdc++.h>using namespace std;int main() { int N; cin>&g原创 2020-08-18 22:38:34 · 109 阅读 · 0 评论 -
PAT_A 1006 Sign In and Sign Out
题解:这道题的关键格式化输入,偷懒将时间视为一个6位数了,直接比较大小。code:#include <iostream>#include <algorithm>#include <bits/stdc++.h>using namespace std;int main() { int M; int h1,h2,m1,m2,s1,s2,h3,m3,s3,h4,m4,s4; string id1,id2,id; int time原创 2020-08-18 17:24:41 · 87 阅读 · 0 评论 -
PAT_A 1005 Spell It Right
题解:这道题的关键是辗转相除法,比较简单,需要注意的就是sum可能为0.由于输入是最大由100个数字组成,因此用string来表示。code:#include<bits/stdc++.h>#include<algorithm>using namespace std;string num[10] = {"zero","one","two","three","four","five","six","seven","eight","nine"};vector<in原创 2020-08-18 16:48:06 · 80 阅读 · 0 评论 -
PAT_A 1004 Counting Leaves
题解:这道题的关键是什么呢?其实就是找树的每一层中非叶结点的总数量然后打印出来,因此简单的BFS就可以了。判断当前队列内的结点是否有孩子,没有孩子就leaf++即可。code:#include <iostream>#include <bits/stdc++.h>#include <algorithm>using namespace std;vector<int>tree[100];void bfs(int node){ bool原创 2020-08-18 16:35:22 · 67 阅读 · 0 评论 -
PAT_A 1003 Emergency
这道题的关键是迪杰斯特拉算法,比较创新的点就是要计算最短路一共有多少条,更新目的地到c1的路径长度时,如果出现了新的最短路,那么直接代替目前计算得到的road数组,如果这条路长度和最短路一致,那么就将到达这条路的方式次数加起来。#include <bits/stdc++.h>#define ll long longusing namespace std;int main() { ll n,m,c1,c2; cin>>n>>m>>c1原创 2020-08-11 11:13:39 · 106 阅读 · 0 评论 -
PAT_A 1002 A+B for Polynomials
这道题的关键就是使用map,输出时注意是按照指数从大到小输出的,然后系数为0的就要剔除出去。#include<stdio.h>#include<iostream>#include <bits/stdc++.h>using namespace std;int main(){ int n1,n2; int a; double b; map<int,double,greater<int>>mp; .原创 2020-08-11 10:07:20 · 93 阅读 · 0 评论 -
PAT_A 1001 A+B Format
题解:这道题挺简单的,没有难点#include<stdio.h>#include<iostream>#include <math.h>using namespace std;int main(){ int a,b; cin>>a>>b; int c = a+b; int flag = c < 0 ? 1 : 0; c = abs(c); string s = to_stri原创 2020-08-06 17:00:07 · 78 阅读 · 0 评论