
C/C++
文章平均质量分 57
daisylliu
这个作者很懒,什么都没留下…
展开
-
HDU1005
Problem Description A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7. Given A, B, and n, you are to calculate the value of f(n). Input转载 2013-08-26 21:56:43 · 610 阅读 · 0 评论 -
Q1.5
/*Write a method to replace all spaces in a string with '%20'.*/ #include #include #include using namespace std; /*method1*/ string replaceSpace(string s) { int len = s.length(); int lent = len原创 2013-11-10 14:52:37 · 724 阅读 · 0 评论 -
Q1.3
/*Design an algorithm and write code to remove the duplicate characters in a string without using any additional buffer. NOTE: One or two additional variables are fine. An extra copy of the array is n原创 2013-11-10 10:43:55 · 756 阅读 · 0 评论 -
Q1.1
Implement an algorithm to determine if a string has all unique characters. What if you can not use additional data structures? 实现一个算法来判断一个字符串的字符是否唯一(即没有重复).不能使用额外的数据结构.(即只使用基本的数据结构) 方法1(O(n^2)):原创 2013-11-07 00:33:09 · 599 阅读 · 0 评论 -
Q1.2
/*Write code to reverse a C-Style String.(C-String means that "abcd" is represented as five characters, including the null charater.)*/ #include #include using namespace std; void swap(char &a, ch原创 2013-11-07 01:16:20 · 504 阅读 · 0 评论 -
Q1.6
/*Given an image represented by an NxN matrix, where each pixel in the image is 4 bytes, write a method to rotate the image by 90 degrees. Can you do this in place?*/ /* 1 2 3 4 1 5转载 2013-11-15 18:20:30 · 585 阅读 · 0 评论 -
整数顺序文件查找至少出现两次的整数
《Programming Pearls》 2.2 给定包含4300000000个32位整数的顺序文件,如何找出一个出现至少两次的整数? 【方法一】 思路:考虑两个条件 1.所有的整数都存储在顺序文件中,因此,读取文件的次数将明显影响算法的效率; 2.顺序文件中包含的整数个数为4300000000,如果全部读取放在内存中的话,必须要考虑内存空间因素。 解决方案: 由上面的问题,原创 2013-09-27 16:57:58 · 1524 阅读 · 2 评论 -
使用位逻辑运算实现位向量并实现位图排序
[Programming Pearls]1.2 & 1.3 给定一个整型(32位)数组,输入一个参数i,然后设置数组的i位(bit位)是1,或者对第i位清零,或者探测第i位的值。使用位逻辑运算(例如与、或、移位)来实现位向量。 // 如何使用位逻辑运算(例如与、或、移位)来实现位向量 // 下面的函数使用常量来设置、清除以及测试位值 // 将位图存储在一个整型数组里面 #define B原创 2013-09-27 12:00:12 · 735 阅读 · 0 评论 -
马的走法
Description 在一个4*5的棋盘上,输入马的起始位置坐标(纵、横),求马能返回初始位置的所有不同走法的总数(马走过的位置不能重复,马走“日”字)。 Input 多个测试数据。 每组2个数字 Output 输出不同走法的总数。 Sample Input 2 2 Sample Output 4596原创 2013-09-08 21:25:30 · 627 阅读 · 0 评论 -
Q1.4
/*Write a method to decide if two strings are anagrams or not.*/ /*写一个函数判断两个字符串是否是变位词*/ /*变位词(anagrams)指的是组成两个单词的字符相同,但位置不同的单词.比如abbcd和abcdb就是一对变位词*/ /*method1: 由于组成变位词的字符是一模一样的,所以按照字典序排序后,两个字符串也就相等了转载 2013-11-10 11:08:40 · 669 阅读 · 0 评论