原创 PAT 1076. Forward on Weibo (30)

#include<iostream> #include<queue> #include<vector> using namespace std; struct users{ int size; vector<int> follow;

原创 PAT 1081. Rational Sum(20)

#include<iostream> using namespace std; int n; long a1, b1, a2, b2; long gcd(long a, long b){  if (b < 0) b = -b;  whil

原创 PAT 1082. Read Number in Chinese(25)

//已AC //3 points not passed...是因爲‘0’ #include<iostream> #include<cstring> //#include<algorithm> using namespace std; ch

原创 PAT 1006. Sign In and Sign Out (25)

//排序是不必要的 但是爲了方便也做了#include<iostream> #include<vector> #include<cstring> #include<algorithm> using namespace std; struc

原创 PAT 1086. Tree Traversal Again (25)

 //樹的問題核心是以不同的形式給出,讓你構造出唯一的一棵(二叉)樹,然後再遍歷輸出 #include<iostream> #include<string> using namespace std; int n, cnt = 0; b

原创 PAT 1004. Counting Leaves (30)

<pre class="cpp" name="code">//此題方法很多,算法還是有很大餘地的//有些人的做法是隻用一個int數組將每個結點的父節點存住,但是後面遍歷每層需用一個臨時隊列存儲,在隊列部分略複雜些//還有人是看層數是否更新

原创 PAT 1074. Reversing Linked List

//此題最後一個測試點竟然是有一些“廢點”存在,只要找到next爲-1的結點就可截止,其它點作廢。 //除了依次查找交換不知道有何種排序方法(但也能滿足時間要求)//直接用sort可否實現?#include <iostream>#incl

原创 PAT 1020. Tree Traversals(25)

//這是第二次寫的版本#include<iostream> using namespace std; #define MAX 35 int post_list[MAX],in_list[MAX]; int n; class Node {

原创 PAT 1083. List Grades(25)

 #include<iostream> #include<algorithm> using namespace std; const long N = 999999; struct student{  char name[15];  

原创 PAT 1077. Kuchiguse (20)

 //已AC. //沒加getchar()時有問題 #include<iostream> #include<cstring> #include<algorithm> using namespace std; char tmp1[2

原创 PAT 1073. Scientific Notation(20)

//寫得笨拙,但一次AC #include<iostream> #include<cstring> using namespace std; char num[10010]; int len; bool exp_sign = true;

原创 PAT 1009. Product of Polynomials (25)

#include<iostream> #include<cstdio> #include<vector> using namespace std; float num[2001] = { 0 }; int cnt = 0; int mai

原创 PAT 1014. Waiting in Line (30)

//AC //看了別人的代碼,發現也並不是很複雜 //關鍵是要在入隊時就把每個人的離開時間計算出來,這樣方便多了 #include<iostream> #include<queue> #include<cstdio> #define cu

原创 PAT 1007. Maximum Subsequence Sum (25)

#include<iostream> using namespace std; int k; int arr[10005]; int sum = 0, MAX; int start = 0, dest = 0; int main(){

原创 PAT 1013. Battle Over Cities (25)

#include<iostream> using namespace std; int N, M, K; int road[1000][1000] = { 0 }; int tmp_road[1000][1000] = { 0 }; in