随笔分类 - C++语言
摘要:对于还不明白Dijkstra算法的可以到网上随便搜一下,有大量的资料,同时也可以参看我的另一篇博客:http://blog.csdn.net/doufei_ccst/article/details/7841311,在这篇博客中是以邻接矩阵来实现Dijkstra算法的。用邻接链表数据结构存储的图的Dijstra算法的实现代码可以参看我的代码分享:https://github.com/crazykeyboard/Graph-AdjList-Dijkstra
阅读全文
摘要:从网上看到网易有道2014届校园招聘的笔试题目,简单的做了一下编程和算法部分,都是一些平常遇到的题目,留一个笔记。总共有两道编程题目和一个算法题目,编程题目要求写出可以运行的C/C++代码或者Java代码,第一个编程题如下:(不是太清楚,但勉强能看)对于这道题,应该是考察对于字符串的处理能力,应该是比较基础的题目。从题目的描述我们可以将要转换的字符串组合分成两大类1,普通的字符串,不进行转换,如例子中的h1(两个尖括号中的内容)2,以&开头并且以;(分号)结尾的的字符串,这类字符串需要按照给定的规则进行转换。该类有可以分成两类1)&后面跟#和数字的UNICODE,需要当做一个U
阅读全文
摘要:The Pilots Brothers' refrigeratorTime Limit:1000MSMemory Limit:65536KTotal Submissions:16008Accepted:6035Special JudgeDescriptionThe game “The Pilots Brothers: following the stripy elephant” has a quest where a player needs to open a refrigerator.There are 16 handles on the refrigerator door. Ev
阅读全文
摘要:Flip GameTime Limit:1000MSMemory Limit:65536KTotal Submissions:26203Accepted:11308DescriptionFlip game is played on a rectangular 4x4 field with two-sided pieces placed on each of its 16 squares. One side of each piece is white and the other one is black and each piece is lying either it's black
阅读全文
摘要:Rightmost DigitTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 26061Accepted Submission(s): 10018Problem DescriptionGiven a positive integer N, you should output the most right digit of N^N.InputThe input contains several test cases. The first line
阅读全文
摘要:Humble NumbersTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 13689Accepted Submission(s): 5956Problem DescriptionA number whose only prime factors are 2,3,5 or 7 is called a humble number. The sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16
阅读全文
摘要:The Hardest Problem EverTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 13447Accepted Submission(s): 6123Problem DescriptionJulius Caesar lived in a time of danger and intrigue. The hardest situation Caesar ever faced was keeping himself alive. In
阅读全文
摘要:As Easy As A+BTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 30295Accepted Submission(s): 12993Problem DescriptionThese days, I am thinking about a question, how can I get a problem as easy as A+B? It is fairly difficulty to do such a thing. Of co
阅读全文
摘要:The 3n + 1 problemTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 18197Accepted Submission(s): 6721Problem DescriptionProblems in Computer Science are often classified as belonging to a certain class of problems (e.g., NP, Unsolvable, Recursive). I
阅读全文
摘要:最小公倍数Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 27414Accepted Submission(s): 15184Problem Description给定两个正整数,计算这两个数的最小公倍数。Input输入包含多组测试数据,每组只有一行,包括两个不大于1000的正整数.Output对于每个测试用例,给出这两个数的最小公倍数,每个实例输出一行。Sample Input10 14Sample Output70代码如下:#include
阅读全文
摘要:排序Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 28373Accepted Submission(s): 7854Problem Description输入一行数字,如果我们把这行数字中的‘5’都看成空格,那么就得到一行用空格分割的若干非负整数(可能有些整数以‘0’开头,这些头部的‘0’应该被忽略掉,除非这个整数就是由若干个‘0’组成的,这时这个整数就是0)。你的任务是:对这些分割得到的整数,依从小到大的顺序排序输出。Input输入包含多组
阅读全文
摘要:给定一个单链表,判断其中是否有环,已经是一个比较老同时也是比较经典的问题,在网上搜集了一些资料,然后总结一下大概可以涉及到的问题,以及相应的解法。首先,关于单链表中的环,一般涉及到一下问题:1.给一个单链表,判断其中是否有环的存在;2.如果存在环,找出环的入口点;3.如果存在环,求出环上节点的个数;4.如果存在环,求出链表的长度;5.如果存在环,求出环上距离任意一个节点最远的点(对面节点);6.(扩展)如何判断两个无环链表是否相交;7.(扩展)如果相交,求出第一个相交的节点;下面,我将针对上面这七个问题一一给出解释和相应的代码。1.判断时候有环(链表头指针为head)对于这个问题我们可以采用“
阅读全文
摘要:转载自:http://www.cppblog.com/xyjzsh/archive/2010/11/24/134516.html个人觉得写得很好,转载作为备忘,同时也分享给大家!在C++中,有三种类型的循环语句:for, while, 和do...while, 但是在一般应用中作循环时,我们可能用for和while要多一些,do...while相对不受重视。 但是,最近在读我们项目的代码时,却发现了do...while的一些十分聪明的用法,不是用来做循环,而是用作其他来提高代码的健壮性。1. do...while(0)消除goto语句。通常,如果在一个函数中开始要分配一些资源,然后在中途执行过
阅读全文
摘要:KMP算法的原理,这里我不写,建议参考:http://www.ruanyifeng.com/blog/2013/05/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm.htmlhttp://blog.csdn.net/v_JULY_v/article/details/6545192http://blog.csdn.net/joylnwang/article/details/6778316这篇博客写的非常好,以本人的能力只能写出更烂的解释 .....所以就不再多此一举了,下面仅仅给出两段代码,分别用C++和Python写的(都已经编译通过),希望能对大家有
阅读全文
摘要:写了两个函数,分别借助不同的函数实现,代码的逻辑很简单:#include #include #include //strtok
#include
#include using namespace std; //实现将一个字符串按照分隔符划分成单词
/*
*思路:
*每一个单词的开头也就是第一个非空格的位置,用start = find_first_not_of(' ', end)来得到
*每一个单词的结尾就是从start开始的第一个空格的前一个位置用end = find_first(' ', start)来得到
*/
vector split(const stri
阅读全文

浙公网安备 33010602011771号