c/c++
a18779148177
这个作者很懒,什么都没留下…
展开
-
PAT a1081题解
#include #include using namespace std;typedef long long ll;ll gcd(ll a, ll b){ return b == 0 ? a : gcd(b, a % b);}struct Fraction{ ll up, down;};Fraction reduction(Fraction result){ if原创 2017-07-22 00:09:23 · 517 阅读 · 0 评论 -
PAT a1080题解
#include #include using namespace std;struct Student{ int GE, GI, sum; int r, stuID; int cho[60];}stu[40010];struct School{ int quota; int stuNum; int id[40010]; int lastAdmit;}sch[110原创 2017-07-22 00:08:39 · 787 阅读 · 0 评论 -
PAT a1079题解
#include #include #include using namespace std;const int maxn = 100010;struct node{ double data; vector child;}Node[maxn];int n;double p, r, ans = 0;void DFS(int index, int depth){ if原创 2017-07-22 00:07:48 · 616 阅读 · 0 评论 -
PAT a1078题解
#include #include bool isPrime(int n){ if(n <= 1) return false; int sqr = (int)sqrt(1.0 * n); for(int i = 2; i <= sqr; i++){ if(n % i == 0) return false; } return true;}bool HashTable[10原创 2017-07-22 00:06:43 · 599 阅读 · 0 评论 -
PAT a1077题解
#include #include int n, minLen = 256, ans = 0;char s[100][256];int main(){ scanf("%d", &n); getchar(); for(int i = 0; i < n; i++){ gets(s[i]); int len = strlen(s[i]); if(len < minLen){原创 2017-07-22 00:06:01 · 492 阅读 · 0 评论 -
PAT a1076题解
#include #include #include #include using namespace std;const int MAXV = 1010;struct Node{ int id; int layer;}; vector Adj[MAXV];bool inq[MAXV] = {false};int BFS(int s, int L){ int num原创 2017-07-22 00:04:35 · 799 阅读 · 0 评论 -
PAT a1075题解
#include #include #include using namespace std;const int maxn = 10010;struct Student{ int id; int score[6]; bool flag; int score_all; int solve;}stu[maxn];int n, k, m;int full[6];bool原创 2017-07-22 00:03:35 · 568 阅读 · 0 评论 -
PAT a1074题解
#include #include using namespace std;const int maxn = 100010;struct Node{ int address, data, next; int order;}node[maxn];bool cmp(Node a, Node b){ return a.order < b.order;}int main()原创 2017-07-22 00:02:51 · 547 阅读 · 0 评论 -
PAT a1071题解
#include #include #include using namespace std;bool check(char c){ if(c >= '0' && c <= '9') return true; if(c >= 'A' && c <= 'Z') return true; if(c >= 'a' && c <= 'z') return true; return f原创 2017-07-22 00:02:03 · 542 阅读 · 0 评论 -
PAT a1070题解
#include #include using namespace std;struct Product{ double count; double totalSell; double danjia;}product[1010];bool cmp(Product a, Product b){ return a.danjia > b.danjia;}int main(){原创 2017-07-22 00:00:59 · 300 阅读 · 0 评论 -
PAT a1069题解
#include #include using namespace std;int numAsc(int num){ int qian = num / 1000; int bai = num / 100 % 10; int shi = num / 10 % 10; int ge = num % 10; int a[5]; a[0] = qian; a[1] = bai;原创 2017-07-21 00:10:12 · 504 阅读 · 0 评论 -
PAT a1067题解
#include #include using namespace std;const int maxn = 100010;int pos[maxn];int main(){ int n, ans = 0; scanf("%d", &n); int left = n -1, num; for(int i = 0; i < n; i++){ scanf("%d", &num原创 2017-07-21 00:09:34 · 388 阅读 · 0 评论 -
PAT a1066题解
#include #include using namespace std;struct node{ int v, height; node *lchild, *rchild;} *root;node* newNode(int v){ node* Node = new node; Node->v = v; Node->height = 1; Node->lchild =原创 2017-07-21 00:08:57 · 489 阅读 · 0 评论 -
PAT a1065题解
#include int main(){ int T, tcase = 1; scanf("%d", &T); while(T--){ long long a, b, c; scanf("%lld%lld%lld", &a, &b, &c); long long res = a + b; bool flag; if(a > 0 && b > 0 && res < 0)原创 2017-07-21 00:08:22 · 294 阅读 · 0 评论 -
PAT a1064题解
#include #include using namespace std;const int maxn = 1010;int n, number[maxn], CBT[maxn], index = 0;void inOrder(int root){ if(root > n) return; inOrder(root * 2); CBT[root] = number[inde原创 2017-07-21 00:07:42 · 320 阅读 · 0 评论 -
PAT a1063题解
#include #include using namespace std;const int N = 51;set st[N];void compare(int x, int y){ int totalNum = st[y].size(), sameNum = 0; for(set::iterator it = st[x].begin(); it != st[x].end()原创 2017-07-21 00:07:03 · 315 阅读 · 0 评论 -
PAT a1062题解
#include #include #include using namespace std;struct Student{ char id[10]; int de, cai, sum; int flag;}stu[100010];bool cmp(Student a, Student b){ if(a.flag != b.flag){ return a.flag <原创 2017-07-21 00:06:19 · 461 阅读 · 0 评论 -
PAT a1061题解
#include #include int main(){ char week[7][5] = {"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"}; char str1[65], str2[65], str3[65], str4[65]; gets(str1); gets(str2); gets(str3); gets(str4);原创 2017-07-21 00:05:20 · 320 阅读 · 0 评论 -
PAT a1060题解
#include #include using namespace std;int n;string deal(string s, int& e){ int k = 0; while(s.length() > 0 && s[0] == '0'){ s.erase(s.begin()); } if(s[0] == '.'){ s.erase(s.begin());原创 2017-07-21 00:04:30 · 955 阅读 · 0 评论 -
PAT a1059题解
#include #include const int maxn = 100010;bool isPrime(int n){ if(n <= 1) return false; int sqr = (int)sqrt(1.0 * n); for(int i = 2; i <= sqr; i++){ if(n % i == 0) return false; } return t原创 2017-07-21 00:03:49 · 507 阅读 · 0 评论 -
PAT a1058题解
#include int main(){ long long gallon1, sickle1, knuts1; long long gallon2, sickle2, knuts2; long long gallon3, sickle3, knuts3; int temp1 = 0, temp2 = 0; scanf("%lld.%lld.%lld %lld.%lld.%lld原创 2017-07-20 12:21:42 · 430 阅读 · 0 评论 -
PAT a1056题解
#include #include using namespace std;const int maxn = 1010;struct mouse{ int weight; int R;}mouse[maxn];int main(){ int np, ng, order; scanf("%d%d", &np, &ng); for(int i = 0; i < np; i原创 2017-07-20 12:21:00 · 430 阅读 · 0 评论 -
PAT a1055题解
#include #include #include using namespace std;int Age[100010] = {0};struct Person{ int age, worths; char name[10];}ps[100010], valid[100010];bool cmp(Person a, Person b){ if(a.worths !=原创 2017-07-20 12:20:27 · 700 阅读 · 0 评论 -
PAT a1054题解
#include #include using namespace std;int main(){ int n, m, col; scanf("%d%d", &n, &m); map count; for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++){ scanf("%d", &col); if(count.原创 2017-07-20 12:19:51 · 245 阅读 · 0 评论 -
PAT a1053题解
#include #include #include using namespace std;const int maxn = 110;struct node{ int weight; vector child;}Node[maxn];bool cmp(int a, int b){ return Node[a].weight > Node[b].weight;} int原创 2017-07-20 12:19:17 · 878 阅读 · 0 评论 -
PAT a1052题解
#include #include using namespace std;const int maxn = 100005;struct Node{ int address, data, next; bool flag;}node[maxn]; bool cmp(Node a, Node b){ if(a.flag == false || b.flag == false原创 2017-07-20 12:18:39 · 442 阅读 · 0 评论 -
PAT a1051题解
#include #include using namespace std;const int maxn = 1010;int arr[maxn];stack st;int main(){ int m, n, T; scanf("%d%d%d", &m, &n, &T); while(T--){ while(!st.empty()){ st.pop(); }原创 2017-07-20 12:17:55 · 472 阅读 · 0 评论 -
PAT a1050题解
#include #include char str1[10010];char str2[10010];int main(){ gets(str1); gets(str2); int len1 = strlen(str1); int len2 = strlen(str2); for(int i = 0; i < len1; i++){ int j; for(j = 0原创 2017-07-20 12:17:02 · 294 阅读 · 0 评论 -
PAT a1049题解
#include int main(){ int n, a = 1, ans = 0; int left, now, right; scanf("%d", &n); while(n / a != 0){ left = n / (a * 10); now = n / a % 10; right = n % a; if(now == 0) ans += left * a;原创 2017-07-20 12:16:08 · 330 阅读 · 0 评论 -
PAT a1048题解
#include #include using namespace std;const int N = 1005;int hashTable[N];int main(){ int n, m, a; scanf("%d %d", &n, &m); for(int i = 0; i < n; i++){ scanf("%d", &a); ++hashTable[a]; }原创 2017-07-20 12:15:23 · 399 阅读 · 0 评论 -
PAT a1047题解
#include #include #include #include using namespace std;const int maxn = 40010;const int maxc = 2510;char name[maxn][5];vector course[maxc];bool cmp(int a, int b){ return strcmp(name[a],原创 2017-07-19 17:46:51 · 360 阅读 · 0 评论 -
PAT a1046题解
#include const int MAXN = 100005;int a[MAXN] = {0};int main(){ int n; int sum = 0; scanf("%d", &n); for(int i = 0; i < n; i++){ int dis; scanf("%d", &dis); sum = sum + dis; a[i] = sum原创 2017-07-19 17:45:57 · 556 阅读 · 0 评论 -
PAT a1044题解
#include const int N = 100010;int sum[N];int n, S, nearS = 100000010;int upper_bound(int L, int R, int x){ int left = L, right = R, mid; while(left < right){ mid = (left + right) / 2; if(s原创 2017-07-19 17:45:07 · 489 阅读 · 0 评论 -
PAT a1043题解
#include #include using namespace std;struct node{ int data; node *left, *right;}; void insert(node* &root, int data){ if(root == NULL){ root = new node; root->data = data; root->left原创 2017-07-19 17:44:23 · 298 阅读 · 0 评论 -
PAT a1042题解
#include const int N = 54;char mp[5] = {'S', 'H', 'C', 'D', 'J'};int start[N + 1], end[N + 1], next[N + 1];int main(){ int K; scanf("%d", &K); for(int i = 1; i <= N; i++){ start[i] = i; }原创 2017-07-19 17:43:26 · 329 阅读 · 0 评论 -
PAT a1041题解
#include int a[100010], hashTable[100010] = {0};int main(){ int n; scanf("%d", &n); for(int i = 0; i < n; i++){ scanf("%d", &a[i]); hashTable[a[i]]++; } int ans = -1; for(int i = 0; i < n原创 2017-07-19 17:42:25 · 274 阅读 · 0 评论 -
PAT a1039题解
#include #include #include #include using namespace std;const int N = 40010;const int M = 26 * 26 * 26 * 10 + 1;vector selectCourse[M];int getID(char name[]){ int id = 0; for(int i = 0; i原创 2017-07-19 17:41:45 · 265 阅读 · 0 评论 -
PAT a1038题解
#include #include #include #include using namespace std;const int maxn = 10010;string str[maxn];bool cmp(string a, string b){ return a + b < b + a;}int main(){ int n; cin >> n; for(int原创 2017-07-19 17:40:54 · 359 阅读 · 0 评论 -
PAT a1037题解
#include #include using namespace std;const int maxn = 100010;int coupon[maxn], product[maxn];int main(){ int n, m; scanf("%d", &n); for(int i = 0; i < n; i++){ scanf("%d", &coupon[i]); }原创 2017-07-19 17:40:05 · 292 阅读 · 0 评论 -
PAT a1036题解
#include struct Stu{ char name[15]; char id[15]; char sex; int score;}tmp, min, max;int main(){ min.score = 101; max.score = -1; int n; scanf("%d", &n); for(int i = 0; i < n; i++){ sca原创 2017-07-19 17:39:23 · 229 阅读 · 0 评论