摘要: json数据解析 1.json格式 首先简单介绍下啥是json格式。 JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式。易于人阅读和编写,同时也易于机器解析和生成。它基于JavaScript(Standard ECMA 262 3rd Edition De 阅读全文
posted @ 2018-07-23 20:06 zkang 阅读(730) 评论(0) 推荐(0) 编辑
摘要: 1088. Rational Arithmetic For two rational numbers, your task is to implement the basic arithmetics, that is, to calculate their sum, difference, prod 阅读全文
posted @ 2016-08-14 17:35 zkang 阅读(212) 评论(0) 推荐(0) 编辑
摘要: 1078. Hashing The task of this problem is simple: insert a sequence of distinct positive integers into a hash table, and output the positions of the i 阅读全文
posted @ 2016-08-14 17:29 zkang 阅读(157) 评论(0) 推荐(0) 编辑
摘要: 1090. Highest Price in Supply Chain A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商) everyone involved in moving a 阅读全文
posted @ 2016-08-14 17:21 zkang 阅读(420) 评论(0) 推荐(0) 编辑
摘要: 1064. Complete Binary Search Tree A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties: The left subt 阅读全文
posted @ 2016-08-14 10:05 zkang 阅读(260) 评论(0) 推荐(0) 编辑
摘要: 1009. Product of Polynomials This time, you are supposed to find A B where A and B are two polynomials. Input Specification: Each input file contains 阅读全文
posted @ 2016-08-13 21:07 zkang 阅读(173) 评论(0) 推荐(0) 编辑
摘要: 1002. A+B for Polynomials This time, you are supposed to find A+B where A and B are two polynomials. Input Each input file contains one test case. Eac 阅读全文
posted @ 2016-08-13 20:27 zkang 阅读(119) 评论(0) 推荐(0) 编辑
摘要: 1004. Counting Leaves A family hierarchy is usually presented by a pedigree tree. Your job is to count those family members who have no child. Input E 阅读全文
posted @ 2016-08-13 18:25 zkang 阅读(184) 评论(0) 推荐(0) 编辑
摘要: 1094. The Largest Generation A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level belong to the same gener 阅读全文
posted @ 2016-08-13 17:26 zkang 阅读(165) 评论(0) 推荐(0) 编辑
摘要: 图的邻接表表示及其BFS遍历 有下面这张图: 假设该图为有向图,边的指向均为小序号指向大序号。那么对该图的BFS遍历如下(假设从序号0的节点开始遍历): 遍历结果应为: BFS遍历类似于树的层序遍历,需要用到队列。下面是程序代码: 1.队列定义和相关操作 文件1 queue.h 文件2 queue. 阅读全文
posted @ 2016-08-09 14:13 zkang 阅读(3805) 评论(0) 推荐(0) 编辑
摘要: 图的邻接表表示及其遍历 1.图的结构定义 2.图的建立 3.图的DFS遍历 假设有下面这张图,这个图包含两个连通图。 输入如下: 程序运行结果: 证明程序是正确的。 完整程序代码参见: https://github.com/zkangHUST/DataStructure 阅读全文
posted @ 2016-08-08 17:36 zkang 阅读(8586) 评论(0) 推荐(1) 编辑
摘要: 1024. Palindromic Number A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 123432 阅读全文
posted @ 2016-08-04 11:19 zkang 阅读(270) 评论(0) 推荐(0) 编辑
摘要: 1019. General Palindromic Number A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example 阅读全文
posted @ 2016-08-03 23:11 zkang 阅读(151) 评论(0) 推荐(0) 编辑
摘要: 1007. 素数对猜想 让我们定义 $d_n$ 为:$d_n = p_{n+1} p_n$,其中 pi 是第i个素数。显然有 d1=1 且对于n 1有 $d_n$ 是偶数。“素数对猜想”认为“存在无穷多对相邻且差为2的素数”。 现给定任意正整数$N ( include int isprime(int 阅读全文
posted @ 2016-08-03 21:11 zkang 阅读(136) 评论(0) 推荐(0) 编辑
摘要: 1048. Find Coins Eva loves to collect coins from all over the universe, including some other planets like Mars. One day she visited a universal shoppi 阅读全文
posted @ 2016-08-03 20:43 zkang 阅读(151) 评论(0) 推荐(0) 编辑
摘要: 1037. Magic Coupon The magic shop in Mars is offering some magic coupons. Each coupon has an integer N printed on it, meaning that when you use this c 阅读全文
posted @ 2016-08-03 20:39 zkang 阅读(107) 评论(0) 推荐(0) 编辑
摘要: 1099. Build A Binary Search Tree A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties: The left subtr 阅读全文
posted @ 2016-08-03 20:24 zkang 阅读(140) 评论(0) 推荐(0) 编辑
摘要: 1085. Perfect Sequence Given a sequence of positive integers and another positive integer p. The sequence is said to be a "perfect sequence" if M incl 阅读全文
posted @ 2016-08-03 20:19 zkang 阅读(465) 评论(0) 推荐(0) 编辑
摘要: 1081. Rational Sum Given N rational numbers in the form "numerator/denominator", you are supposed to calculate their sum. Input Specification: Each in 阅读全文
posted @ 2016-08-03 20:16 zkang 阅读(167) 评论(0) 推荐(0) 编辑
摘要: 1069. The Black Hole of Numbers For any 4 digit integer except the ones with all the digits being the same, if we sort the digits in non increasing or 阅读全文
posted @ 2016-08-03 20:11 zkang 阅读(6630) 评论(0) 推荐(0) 编辑
摘要: 1015. Reversible Primes A reversible prime in any number system is a prime whose "reverse" in that number system is also a prime. For example in the d 阅读全文
posted @ 2016-08-03 20:07 zkang 阅读(219) 评论(0) 推荐(0) 编辑
摘要: PAT B 1034. 有理数四则运算 本题要求编写程序,计算2个有理数的和、差、积、商。 输入格式: 输入在一行中按照“a1/b1 a2/b2”的格式给出两个分数形式的有理数,其中分子和分母全是整型范围内的整数,负号只可能出现在分子前,分母不为0。 输出格式: 分别在4行中按照“有理数1 运算符 阅读全文
posted @ 2016-08-03 12:23 zkang 阅读(295) 评论(0) 推荐(0) 编辑
摘要: 萌萌哒表情符号通常由“手”、“眼”、“口”三个主要部分组成。简单起见,我们假设一个表情符号是按下列格式输出的: 现给出可选用的符号集合,请你按用户的要求输出表情。 输入格式: 输入首先在前三行顺序对应给出手、眼、口的可选符号集。每个符号括在一对方括号[]内。题目保证每个集合都至少有一个符号,并不超过 阅读全文
posted @ 2016-08-03 11:57 zkang 阅读(1548) 评论(0) 推荐(0) 编辑
摘要: 1.题目描述 本题要求将给定的N个正整数按非递增的顺序,填入“螺旋矩阵”。所谓“螺旋矩阵”,是指从左上角第1个格子开始,按顺时针螺旋方向填充。要求矩阵的规模为m行n列,满足条件:m n等于N;m =n;且m n取所有可能值中的最小值。 输入格式: 输入在第1行中给出一个正整数N,第2行给出N个待填充 阅读全文
posted @ 2016-08-02 19:45 zkang 阅读(1067) 评论(0) 推荐(0) 编辑
摘要: 题目描述 某游戏规则中,甲乙双方战斗,每一回合总能分出胜负,游戏规定: 1.失败的一方要将自己体力值的1/4加给胜利的一方。 2.游戏开始时,甲的体力值是1000,乙的体力值是2000。 3.每一回合,甲乙胜利的概率均为50%。 求解4个回合后,双方体力值之差小于1000的概率。 分析 每一回合结束 阅读全文
posted @ 2016-08-02 14:11 zkang 阅读(292) 评论(0) 推荐(0) 编辑
摘要: 八皇后问题,是一个古老而著名的问题,是回溯算法的典型案例。该问题是国际西洋棋棋手马克斯·贝瑟尔于1848年提出:在8×8格的国际象棋上摆放八个皇后,使其不能互相攻击,即任意两个皇后都不能处于同一行、同一列或同一斜线上,问有多少种摆法。 假设八个皇后的位置分别用X1到X8表示,那么Xi可以取的值为1~ 阅读全文
posted @ 2016-08-02 09:42 zkang 阅读(290) 评论(0) 推荐(0) 编辑
摘要: 1.基本思路 层序遍历的基本思路就是, 1.根节点入队列。 2.根节点出队,同时将根节点左儿子和右儿子入队 3.结点出队,同时将该节点的左儿子和右儿子入队 4.重复3直到队列为空 2.算法实现 void layerprint(struct TreeNode r) { struct queue q1; 阅读全文
posted @ 2016-06-27 19:22 zkang 阅读(2128) 评论(0) 推荐(0) 编辑
摘要: 数据结构二叉树遍历之非递归算法-石锅拌饭的博客二叉树遍历的递归算法-石锅拌饭的博客二叉树的递归建立Binary Trees - Stanford CS Education LibraryBinary Trees(PDF) - Stanford CS Education Librar... 阅读全文
posted @ 2016-03-24 23:11 zkang 阅读(119) 评论(0) 推荐(0) 编辑
摘要: 二叉树总结 1. 二叉树的重要性质 一个二叉树的第i层最多有2i−1个结点(i>=1) 深度为k的二叉树最多有2k−1个结点(k>=1) 对于任何非空二叉树有n0个叶结点,n2个度为2的结点,那么总有关系: n0=n2+1 2.对二叉树的操作 Boolean IsEmpty(BinTree BT); 阅读全文
posted @ 2016-03-24 22:28 zkang 阅读(156) 评论(0) 推荐(0) 编辑
摘要: 二分法 例:假设有一个容量为n+1开始的数组,从小到大存储了n个数(从下标1开始存储)。给定给定数m,求出数组中值为m的元素的下标,如果未找到则返回0。 分析: 以11个数进行分析。 首先令左边界为left=1,右边界为right=11,mid=(left+right)/2 即为6,判断m跟num[ 阅读全文
posted @ 2016-03-24 17:27 zkang 阅读(319) 评论(0) 推荐(0) 编辑
摘要: Lily上课时使用字母数字图片教小朋友们学习英语单词,每次都需要把这些图片按照大小(ASCII码值从小到大)排列收好。请大家给Lily帮忙,通过C语言解决。Lily使用的图片包括”A”到”Z”、”a”到”z”、”0”到”9”。输入字母或数字个数不超过1024。Lily的所有图片按照... 阅读全文
posted @ 2016-03-23 23:42 zkang 阅读(386) 评论(0) 推荐(0) 编辑
摘要: 计算字符串最后一个单词的长度,单词以空格隔开。字符串长度小于128输入样例 hello world输出样例 5程序代码:#include#includeusing namespace std;int main(){ char str[128]; gets(str); ... 阅读全文
posted @ 2016-03-23 23:23 zkang 阅读(507) 评论(0) 推荐(0) 编辑
摘要: 将一个字符串str的内容颠倒过来,并输出。str的长度不超过100个字符。 如:输入“I am a student”,输出“tneduts a ma I”。输入参数: inputString:输入的字符串返回值: 输出转换好的逆序字符串输入样例: I am a student输出样... 阅读全文
posted @ 2016-03-23 21:29 zkang 阅读(958) 评论(0) 推荐(0) 编辑
摘要: 关于complex类的定义:#includeusing namespace std;class complex{ public: complex() {real=0;im=0;} complex(float a,float b):re... 阅读全文
posted @ 2016-03-23 20:33 zkang 阅读(325) 评论(0) 推荐(0) 编辑
摘要: 输入一个字符串和一个非负整数N,要求将字符串循环左移N次。输入格式:输入在第1行中给出一个不超过100个字符长度的、以回车结束的非空字符串;第2行给出非负整数N。输出格式:在一行中输出循环左移NN次后的字符串。输入样例:Hello World!2输出样例:llo World!He程... 阅读全文
posted @ 2016-03-23 00:24 zkang 阅读(1144) 评论(0) 推荐(0) 编辑
摘要: 我们已经知道了将N个整数按从小到大排序的冒泡排序法。本题要求将此方法用于字符串序列,并对任意给定的K(K#include#includeusing namespace std;int main(){ int N,k; cin>>N>>k; char temp[20... 阅读全文
posted @ 2016-03-22 22:43 zkang 阅读(452) 评论(0) 推荐(0) 编辑
摘要: 乌龟与兔子进行赛跑,跑场是一个矩型跑道,跑道边可以随地进行休息。乌龟每分钟可以前进3米,兔子每分钟前进9米;兔子嫌乌龟跑得慢,觉得肯定能跑赢乌龟,于是,每跑10分钟回头看一下乌龟,若发现自己超过乌龟,就在路边休息,每次休息30分钟,否则继续跑10分钟;而乌龟非常努力,一直跑,不休息... 阅读全文
posted @ 2016-03-22 11:39 zkang 阅读(738) 评论(0) 推荐(0) 编辑
摘要: 今天重点学习了一下关于字符串的一些知识点,总结一下如下:1.’\0’的ASCII值为0可以利用这个特性判断字符串是否到末尾了。假设有字符数组str[],下面的while()可以判断字符数组是否结束。int i = 0;while(str[i]){ printf("%c",st... 阅读全文
posted @ 2016-03-22 00:00 zkang 阅读(128) 评论(0) 推荐(0) 编辑
摘要: 为了准备找工作,买了本《程序员面试宝典》看看,结果发现这本书里面错漏的地方实在是太多了。记录一下,希望对后来的人有所帮助。 1.184页,“面试官会节和程序对你的思维能力进行考量。”中“节”字写错,应改为“结”。2.185页,面试例题2:编程实现单链表删除节点。但是给的示意图却是插... 阅读全文
posted @ 2016-03-21 22:58 zkang 阅读(521) 评论(0) 推荐(0) 编辑
摘要: 输入一个整数,输出每个数字对应的拼音。当整数为负数时,先输出“fu”字。十个数字对应的拼音如下:0: ling1: yi2: er3: san4: si5: wu6: liu7: qi8: ba9: jiu输入格式:输入在一行中给出一个整数,如:1234。提示:整数包括负数、零和正... 阅读全文
posted @ 2016-03-21 18:09 zkang 阅读(610) 评论(0) 推荐(0) 编辑