- 博客(10)
- 收藏
- 关注
原创 PAT 1064 Complete Binary Search Tree
这道题用数组表示法表示完全二叉树,写的神清气爽啊,抓住两点,首先,下标1开始,那么左子树是2*i,右子树是2*i+1. 然后是二叉排序树的性质,二叉排序树的中序遍历是一个排序好的数组。然后我们就可以用中序遍历填好完全二叉树数组,最后按序输出就是层次遍历了。#include #include #include using namespace std; int N; int arr[1005];
2015-02-28 21:18:42 311
原创 PAT 1085 Pefect Sequence
查了一下数据范围: bool型为布尔型,占1个字节,取值0或1。 BOOL型为int型,一般认为占4个字节,取值TRUE/FALSE/ERROR。 sbyte型为有符号8位整数,占1个字节,取值范围在128~127之间。 bytet型为无符号16位整数,占2个字节,取值范围在0~255之间。 short
2015-02-23 10:51:50 448
原创 SET的用法
set中插入一个元素: insert(s1,str1); set中删除一个元素可以这样写 :√ 1 2 3 4 5 6 7 8 9 for (set::iterator it = numSet.begin(),prev = it;it!=numSet.end();)
2015-02-21 14:35:47 412
原创 PAT 1084 Broken Keyboard
其实代码复杂度还是蛮高的,不过,数据范围小呀~~嘿嘿,主要用了set#include #include #include #include using namespace std; char str1[88]; char str2[88]; set s1,s2; set dif; char upper(char c){ char ans=c; if (c='a') {
2015-02-21 14:29:00 307
原创 PAT1083 List Grades
#include #include #include #include #include using namespace std; struct Stu{ char name[15]; char id[15]; int grade; bool operator <(const Stu & b) const { return grade
2015-02-20 17:59:37 364
原创 PAT 1080 Graduate Admission
这道题很简单,但是做了很久。这里想贴两个版本,第一个是不完全正确的,但是仍然想保留下来提醒自己注意留意容易忽略的小细节! 总结一下出错的地方,首先是要注意保留学生id,然后要注意在录取环节千万不要把循环变量i当做学生id。个人感觉保存学生rank比保存未排序的stu要好,不容易出错。 #include #include #include #include using namespac
2015-02-20 15:25:31 374
原创 PAT1081Rational Sum
这道题只要知道最大公约数和最小公倍数的求法就可以做得出来,但是要考虑的输出细节比较繁琐,代码写的很丑啦,不过总算是全部case通过了。// // main.cpp // PTT2 // // Created by 潘婷婷 on 15-2-1. // Copyright (c) 2015年 潘婷婷. All rights reserved. // #include #include #
2015-02-19 16:15:19 449
原创 PAT1079 Total Sales of Supply Chain
// // main.cpp // PTT2 // // Created by 潘婷婷 on 15-2-1. // Copyright (c) 2015年 潘婷婷. All rights reserved. // #include #include #include using namespace std; int Tree[100000]; int retailer[100000]
2015-02-10 17:41:41 428
原创 PAT1078 Hashing
#include #include #include using namespace std; int hashtable[10000]; int isPrime(int x){ if (x==0||x==1) { return 0;//0: not prime; } if (x==2) { return 1; } i
2015-02-02 21:26:33 344
转载 PAT1077
#include #include #include using namespace std; int main(){ int n; char s[500]; string next,suffix; // freopen("/Users/pantingting/Documents/code/data/input", "r", stdin); scanf
2015-02-02 15:35:41 373
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人