随笔分类 - 算法与数据结构
摘要:样例输入 11Xo 6*E 样例输出 代码 #include <cstdio> #define MAX 80 char buf[MAX][MAX]; void mySwap(int& a, int& b) { int temp = a; a = b; b = temp; } void drawLin
阅读全文
摘要:判断闰年 地球绕太阳转一周的时间实际是365天5小时48分46秒。算下来,每四年会多出来一天,所以加到那一年的二月。但是这样算,又多算了一点点时间。于是,又规定,整百的年份计算闰年除以400。这样,我们的历法才能最大程度的和地球绕太阳转契合。 总之:非整百年份除以4无余数;整百年份除以400无余数
阅读全文
摘要:索引 是否同一棵二叉搜索树 Root of AVL Tree Complete Binary Search Tree 二叉搜索树的操作集 第四周编程作业 是否同一棵二叉搜索树 #include <stdio.h> #include <stdlib.h> #include <stdbool.h> #i
阅读全文
摘要:索引 1、树的同构 2、List Leaves 3、Tree Traversals Again 用堆栈实现后序遍历的非递归程序 第三周编程作业 1、树的同构 利用结构数组表示二叉树。 #include <stdio.h> #include <stdlib.h> #include <stdbool.h
阅读全文
摘要:索引 1、两个有序链表序列的合并 2、一元多项式的乘法与加法运算 3、Reversing Linked List 4、Pop Sequence 第二周编程作业 1、两个有序链表序列的合并 List Merge( List L1, List L2 ) { List temp, cur, result;
阅读全文
摘要:题 例题6-2 铁轨(Rails,UVa 514),题目见参考。 #include <cstdio> #include <vector> #include <stack> using namespace std; int main() { int n, x; vector<int> pop_orde
阅读全文
摘要:例子 使用C语言的字符串库,更多请看参考1 #include <cstdio> #include <cstring> int main() { // NOTICE 在处理字符串时,如果越界,通常在编译时并不报错。 // 但是运行时会有未定义的行为。 // 因此要确保字符数组长度大于其存储的字符串长度
阅读全文
摘要:例子 1、scanf VS. getchar #include <cstdio> #include <cstring> int main() { char s[20]; while (scanf("%s", s) == 1) { printf("echo: %s\n", s); } // 但是 sc
阅读全文
摘要:题 习题5-4 复合词(Compound Words,UVa 10391)。完整题目见参考[1] #include <iostream> #include <cstring> #include <string> #include <set> using namespace std; set<stri
阅读全文
摘要:题 例题5-8 Unix is 命令(Unix is,UVA 400)。完整题目见参考[1] #include <iostream> #include <string> #include <algorithm> using namespace std; const int maxcol = 60;
阅读全文
摘要:正文 点运算符 . 例如 item.isbn() 只用于类类型对象。左侧运算对象必须是一个类类型的对象。右侧必须是该类型对象的一个成员名。运算结果是右侧对象指定的成员。 箭头运算符号 -> 例如 (*it).empty(); 是先对it解引用,然后解引用的的结果再执行点运算符。 箭头运算符是对上述表
阅读全文
摘要:例子 书上的原始代码: #include <iostream> using namespace std; struct Point { int x, y; Point(int x = 0, int y = 0): x(x), y(y) { // x(x), y(y) 等价于 // this->x =
阅读全文
摘要:例子 #include <cstdlib> #include <ctime> #include <vector> #include <algorithm> #include <cassert> using namespace std; void fill_random_int(vector<int>
阅读全文
摘要:例子 #include <iostream> #include <queue> #include <vector> using namespace std; struct cmp { bool operator() (const int a, const int b) const { return
阅读全文
摘要:题 例题5-6 团队队列(Team Queue,UVA - 540)。完整题目见参考[1] #include <cstdio> #include <queue> #include <map> using namespace std; const int MAXT = 1000 + 10; int m
阅读全文
摘要:题 集合栈计算机,完整题目见参考[1] 书上的原始代码如下: #include <iostream> #include <vector> #include <map> #include <set> #include <string> #include <stack> #include <algori
阅读全文
摘要:题 完整题目见参考[1]。 #include <iostream> #include <cstdio> using namespace std; int main() { int T, n, num; // 数据组数,商品种数,种商品的数量 float price, sum; // 某种商品的价格,
阅读全文
摘要:题 例题5-3 反片语(Ananagrams, UVa 156)完整题目见参考[1] 思路:首先把未标准化的单词逐个存到一个vector中,在存的过程中,将标准化后的单词,例如RIDE标准化后是deir,通过map存储并统计其出现的次数。然后根据map中所存储的信息进一步从第一个vector中筛选出
阅读全文
摘要:题&例子 vector的拷贝 #include <cstdio> #include <string> #include <vector> #include <iostream> using namespace std; void print(string lable, vector<int> &v)
阅读全文
摘要:题 例题5-2 木块问题。要区分onto和over,onto是要a与b直接接触,over则不需要。以及,move某木块时,要把它上面的木块全部归位,而pile某木块则不需要。 #include <cstdio> #include <string> #include <vector> #include
阅读全文