- 博客(53)
- 资源 (4)
- 收藏
- 关注
原创 【php】读文件找出特定字符
<?php function aType($x){ $tmp = ord($x); if($tmp>=97 && $tmp<=122){ return 0;// } if($tmp >=65 && $tmp <=90){ return 1; } return 2; } $fin=fopen("5M.txt","r"); $end=mi
2014-04-03 13:58:58
627
原创 二叉树的深度遍历和广度遍历
#include #include #include #include #include using namespace std;#define Element char#define format "%c"typedef struct Node { Element data; struct Node *lchild; struct Node *rchil
2014-03-31 17:11:59
597
原创 数字三角形问题
给定一个由n行数字组成的数字三角形。试设计一个算法,计算出从三角形的顶至底的一条路径,使该路径经过的数字总和最大。并分析起计算复杂性。分析一个数字三角形宝塔,三角形中的数字是不超过100的整数。要从顶端走到底层,每一步可以向下或者右斜线向下走。如34 810 4 92 1 10 22 #include #include int m
2014-03-31 15:51:03
949
原创 杨氏查找矩阵
1 2 53 4 76 8 9从左到右递增,从上到下递增。如果要查找元素应该如何查找。#includeusing namespace std;#define COL 3#define ROW 3bool Young(int a[][COL],int search){ int i =0,j = COL-1; int tmp = a[i][j];
2013-12-30 20:10:09
497
原创 字符串压缩
压缩字段的格式为"字符重复的次数+字符"。例如:字符串"xxxyyyyyyz"压缩后就成为"3x6yz"。要求实现函数: void stringZip(const char *pInputStr, long lInputLen, char *pOutputStr); 输入pInputStr: 输入字符串lInputLen: 输入字符串长度 输出 pOutp
2013-12-30 19:31:07
1786
原创 筛子法求质数
给你一个自然数N,求[6,N]之内的所有素数中,两两之和为偶数的那些偶数。#includeusing namespace std;//筛子法求质数 可以参考亲和数 //6~N的质数,打印两两质数为偶数的所有这些偶数//因为质数除开2以外都是奇数,那么大于6的偶数都是奇数,那么把6~N之间的质数都求出来,打印两两的和就可以了。 int main(){ cout <
2013-12-27 18:31:38
2115
3
原创 丑数
只包含因子2,3,5的数叫丑数,求从小到大顺序的第1500个丑数,例如6,8都是丑数,但14不是。因为它包含因子7。习惯上我们认为1是丑数。思路:丑数肯定是由丑数*2或3或5生成的。由空间换时间的做法。#includeusing namespace std;int Min(int num1,int num2,int num3){ int min=(num1
2013-12-27 17:36:24
507
原创 【Cracking the coding interview】Q1.8(旋转字符串)
Assume you have a method isSubstring which checks if one word is a substring of another. Given two strings, s1 and s2, write code to check if s2 is a rotation of s1 using only one call to isSubstring
2013-12-23 21:52:04
500
原创 【Cracking the coding interview】Q1.7(矩阵置0)
Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column is set to 0.写一个函数处理一个MxN的矩阵,如果矩阵中某个元素为0,那么把它所在的行和列都置为0.#include #include #include using namespa
2013-12-23 21:44:04
765
原创 【Cracking the coding interview】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?一张图像表示成NxN的矩阵,图像中每个像素是4个字节,写一个函数把图
2013-12-23 20:21:04
546
原创 【Cracking the coding interview】Q1.5(替换字符串)
Write a method to replace all spaces in a string with ‘%20’.写一个函数,把字符串中所有的空格替换为%20 。
2013-12-23 20:18:20
411
原创 【Cracking the coding interview】Q1.4(变位词)
Write a method to decide if two strings are anagrams or not.写一个函数判断两个字符串是否是变位词。O(n)的算法,声明个数组来统计出现的次数#include #include #include using namespace std;bool isAnagram(string x, string y){
2013-12-23 19:43:23
623
原创 【Cracking the coding interview】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 not
2013-12-23 19:18:20
537
原创 【Cracking the coding interview】Q1.2(反转字符串)
原文:Write code to reverse a C-Style String. (C-String means that “abcd” is represented as five characters, including the null character.)写代码翻转一个C风格的字符串。(C风格的意思是"abcd"需要用5个字符来表示,包含末尾的 结束字符)思
2013-12-23 17:56:48
677
原创 【Cracking the coding interview】Q1.1(字符唯一)
读了Hawstein大神的大作,读书笔记记录之,膜拜大神用,给自己增些知识。Implement an algorithm to determine if a string has all unique characters. What if you can not use additional data structures?实现一个算法来判断一个字符串中的字符是否唯一思路:用最小的数
2013-12-23 17:34:12
702
原创 【高精度求幂】
思路:思路类似大数乘法,因为计算机的double和float都有位数精度限制,所以我们只能转化成字符串来处理,最后结果也用字符串来保存。这是poj的1001题//Memory Time //1232K 0MS #include#includeusing namespace std;const int size=1000; //大数位数void mult(cha
2013-12-17 17:06:56
695
原创 【大数乘法】
大数乘法的思路:用数组或者字符串来实现大数的乘法,因为超出了单个数的存储限制,用字符串或者数组来模拟进位,保存结果#include #include using namespace std;void multiply(const char *a,const char *b); int main(){ string num1,num2; //
2013-12-17 17:04:04
570
原创 【php】下载文件
php下载文件注意:1中文名的转码2._SEVER 3.文件操作<?php //函数说明 //参数说明 $file_name 文件名 // $file_sub_dir "/xxx/xxx/" function down_file($file_name,$file_sub_dir){ //$file_name="小米.jpg"; /
2013-12-16 19:13:09
553
原创 重建二叉树
前序 a b d c e f中序 d b a e c f 重建二叉树,并打印后续 d b e f c a #include #include #define TREELEN 6struct NODE{ NODE* pLeft; NODE* pRight; char chValue; }; void R
2013-12-14 16:36:02
548
原创 [codility]CountMultiplicativePairs
Count the number of pairs (A, B) such that A * B > A + B.More formally, A[I] and B[I] represent C[I] = A[I] + B[I] / 1,000,000.For example, consider the following arrays A and B:
2013-12-13 16:10:42
3926
原创 [codility]MinAbsSumOfTwo
Find the minimal absolute value of a sum of two elements. A[0] = -8 A[1] = 4 A[2] = 5 A[3] =-10 A[4] = 3the function should return |(−8) + 5| = 3.Assume that
2013-12-13 16:06:27
1568
原创 [codility]equi
Find an index in an array such that its prefix sum equals its suffix sum.A[0] + A[1] + ... + A[P−1] = A[P+1] + ... + A[N−2] + A[N−1].A[0] = -7 A[1] = 1 A[2] = 5A[3] = 2 A[4] =
2013-12-13 15:54:26
1114
原创 【双向链表】水浒英雄
双向链表可以解决的问题可以完成自我删除,效率相对高,不需要辅助结点 双向链表完成英雄排行管理 查询英雄 添加英雄 删除英雄 修改英雄 <?php //使用php的面向对象的方式来完成 class Hero{ public $pre=null;//表示指向前一个节点的引用 public $no; public $name;
2013-12-10 11:54:45
616
原创 【栈】实现高级计算器
实现一个计算器9+2*8-230+2*6-17*2-3*5-2 <?php// $exp=$_GET['exp'];// $exp='9+2*8-3'; //[人眼睛3+12-2 =>15-2=>13]// $exp='304+10*6-10'; $exp='71*2-50*3-3-67*6+80';//-333 $numsSta
2013-12-09 23:22:58
641
原创 【栈】数组模拟栈的操作
用php实现的模拟栈的操作 使用数组来模拟栈的各种操作 <?php class MyStack{ private $top=-1;//默认是-1,表示该栈是空的 private $maxSize=5;//$maxSize表示栈的最大容量 private $stack=array(); //注意类里面的变量一定要用$this->xxx,不
2013-12-09 18:13:01
712
原创 【环形链表】丢手帕问题
小朋友丢手帕问题,小朋友的编号(1,2,...,n) ,从k号小朋友开始数,从1开始数到m,当数到m的小朋友出列(1以下是php的环形链表实现方法 约瑟夫问题 <?php class Child{ public $no; public $next=null; public function __construct($no){ $th
2013-12-09 17:17:36
608
原创 【单链表】curd-水浒英雄排行榜
学习了下韩总的算法课,自己记了下笔记,手敲了一下,很有感触。1、单链表的构造2、单链表的添加3、单链表的删除4、单链表的更新 单向链表完成英雄排行管理 查询英雄 添加英雄 删除英雄 修改英雄 <?php class Hero{ public $no;//排名 public $name;//名字 public
2013-12-09 13:19:45
559
原创 memcache学习笔记
Memcached技术介绍:memcached是一种缓存技术, 他可以把你的数据放入内存,从而通过内存访问提速,因为内存最快的, memcached技术的主要目的提速,在memachec 中维护了一张大的hashtable表 ,该表是在内存,表的结构是key value字串 (字串,数值,数组,对象,布尔,二进制数据,null)原理说明:windows下
2013-12-05 19:02:10
2451
原创 【穷举】5 5 5 5 5=5填入操作符
填入合适的操作符使得 5 5 5 5 5=5可以填入+ - * / 不能添加括号。代码如下#include #include int main(){ char oper[]={' ','+','-','*','/'}; int i[5]; int sign=1,j,count=0; int num[]={0,5,5,5,
2013-12-05 13:03:06
3564
原创 彻底搞定c指针
一直对c指针心怀崇敬,因为总是容易糊涂。看了某大神写的《彻底搞定c指针》更是心怀感激,整理笔记一篇,以表谢意。1、首先问问自己指针到底是什么东西?2、指针和数组名的区别是啥?数组名也是指针,但是不可修改。是指针常量!3、const int *pi与int *const pi有何区别?const int *pi 这里const 修饰了 *pi,所以*pi不能被
2013-11-28 00:06:04
1696
原创 awk快速学习
一直久仰awk的大名,但一直没有学习,果然是要用的时候学习起来会比较快。因为要帮人写个小程序,就快速学习了下。 首先不知道如何入手,我先看看语法吧。看电子书:《I love awk》熟悉下语法 awk最牛逼的就是处理数据,如果能像数据库一样select group啊什么的,就好了,于是我参考了这篇文章: http://blog.youkuaiyun.com/sunny521
2013-11-27 15:20:38
715
原创 全组合
1 2 3 4打印所有的数字组合12341 21 31 42 32 43 41 2 31 3 42 3 41 2 3 4#include #include using namespace std;vector result;void combination(int a[],int number,int inde
2013-11-25 01:09:11
526
原创 二叉树转双向链表
输入一棵二元查找树,将该二元查找树转换成一个排序的双向链表。要求不能创建任何新的结点,只调整指针的指向。10/ \6 14/ \ / \4 8 12 16转换成双向链表#include using namespace std;struct BSTreeNode{ int m_nValue; // value of node BSTree
2013-11-24 23:42:24
539
原创 不用加减乘除做加法
不用加减乘除做加法,那我们还能用啥,位运算吧!#includeusing namespace std;int add (int num1,int num2){ int sum,carry; do{ sum=num1^num2; carry=(num1&num2)<<1; num1=sum
2013-11-23 11:19:48
518
原创 亲和数
亲和数是一种古老的数。遥远的古代,人们发现某些自然数之间有特殊的关系:如果两个数a和b,a的所有除本身以外的因数之和等于b,b的所有除本身以外的因数之和等于a,则称a,b是一对亲和数。220=1+2+4+71+142=sum[284], 284=1+2+4+5+10+11+20+22+44+55+110=sum[220]这样220和284就是一对亲和数。
2013-11-22 21:17:50
1262
原创 【排序】快速排序 冒泡排序 选择排序
快排public class Quicksort { public int getMiddle(Integer[] list, int low, int high) { int tmp = list[low]; //数组的第一个作为中轴 while (low < high) { while (low tmp) { high--; } list[low
2013-11-21 21:52:45
555
原创 【回溯】八皇后
回溯方法#include #include #define N 8 int column[N+1]; int rup[2*N+1]; int lup[2*N+1]; int queen[N+1]={0}; int num; void backtrack(int); int main() { int i; num=0; for(i=1;i
2013-11-21 20:24:53
624
原创 【回溯】全排列
实际上是一种深度优先的算法。回溯的思想:撞了南墙就回头,直到罗马,到了罗马一回头就是来时的路。#include using namespace std;void swap(int &a,int &b)//交换连个元素{ int tem; tem = a; a = b; b = tem;}int sum=0;void cal(int *a,
2013-11-21 20:11:56
980
原创 【回溯】二叉树求和的所有路径
二叉树求和的所有路径,比如 例如 输入整数22和如下二元树 10 / \ 5 12 / \ 4 7 则打印出两条路径:10,12和12,5,7#include#include#include using namespace std;static int sum(0);static int count(0);
2013-11-21 20:05:34
2017
web service经典电子书(全英文)
2008-11-14
osworkflow入门范例
2008-04-12
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人