![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
笔试面试题
看星星灰
这个作者很懒,什么都没留下…
展开
-
用位运算实现加减乘除(C)
#include using namespace std;int plus(int num1,int num2 ){ return num2 ? plus((num1^num2),(num1&num2)<<1):num1;}int negtive(int a) //取补码 { return plus(~a, 1); } int Sub(int a, in原创 2013-05-20 10:59:42 · 723 阅读 · 0 评论 -
多层json数据编码转换
function tb_json_convert_encoding($m, $from, $to) { switch(gettype($m)) { case 'integer': case 'boolean': case 'float': case 'double': case 'NULL': return $m;原创 2013-12-18 11:54:34 · 675 阅读 · 0 评论 -
并查集用法一例
题目:有一个相似属性列表,每一行有一些属性,属性间"\t"分割。若某两行有一个属性相同,则认为他们都相似,要求将其合并。比如相似属性表:生日 出生日期 出生日身高 身长出生年月日 出生时间 出生日期我们要做的是合并为 “生日 出生日期出生日期 出生年月日出生时间”code如下:#!/usr/bin/env python#!-*- coding:ut原创 2013-10-24 13:17:43 · 463 阅读 · 0 评论 -
N皇后高效算法
#include #include #include long sum = 0, upperlim = 1;void test(long row, long ld, long rd){ if (row != upperlim) { long pos = upperlim & ~(row | ld | rd); while (pos) { long p =转载 2013-05-30 15:52:30 · 484 阅读 · 0 评论 -
邻接表和邻接矩阵
//graph.htypedef int InfoType;#define MAXV 100//最大顶点个数//定义邻接矩阵类型typedef struct{ int no;//顶点标号 InfoType info;//顶点其他信息,这里用于存放权值}VertexType;//顶点类型typedef struct//图的定义{ int edges[MAXV]原创 2013-05-30 15:00:08 · 710 阅读 · 0 评论 -
static this指针 一例
#include using namespace std;class Myclass{public:Myclass(int a,int b,int c);void GetSum() ;//{cout<<sum<<endl;};private:int a,b,c;static int Sum;//声明静态数据成员};int Myclass::Sum=0;//定义并初始化静态数据原创 2013-05-30 14:53:25 · 700 阅读 · 0 评论 -
0-1背包问题
#includeusing namespace std;#define NEM 5//每个物品的重量#define WI 10//背包总容量int max(int a,int b){ return a>b?a:b;}int main(){ int w[NEM]={0}; cout<<"please put in the wight of every原创 2013-05-15 15:50:51 · 506 阅读 · 0 评论 -
大数乘法
#include #include using namespace std; void multiply (const char *a, const char *b){ int i,j,la,lb; la=strlen(a); lb=strlen(b); int *s=(int *)malloc(sizeof(int)*(la+lb)); //int*s=new i原创 2013-05-14 17:05:16 · 443 阅读 · 0 评论 -
统计1到n中1的出现个数
例如1到12中一出现了5次:1,10,11,12#includeusing namespace std;int numof1(int n){ int m = 0; while(n){ m +=((n % 10 == 1)?1:0); n = n / 10; } return m; } int ma原创 2013-05-27 15:20:07 · 575 阅读 · 0 评论 -
快速排序算法
#include using namespace std;void exchang(int *a,int *b){ int tmp=*a; *a=*b; *b=tmp;}int patition(int a[],int p,int r){ int x=a[r]; int i=p-1; int tmp; for(int j=p;j<=r-1;j++){ if(a[j]<=x原创 2013-05-27 19:16:40 · 417 阅读 · 0 评论 -
八皇后问题
#include#includeusing namespace std;#define N 100//n皇后int sum=0;//第几个解int x[N]={0};//x[i]=j代表在第i行的j列放置皇后 int judge(int k) //判断新加皇后是否符合要求{ for(int i=1;i<k;i++) if(abs(k-i)原创 2013-05-23 17:03:11 · 630 阅读 · 0 评论 -
求字符串中满足所有字符个数相等的最长子串长度
求字符串中各个字符数相等的最长子串,一种O(n)方法原创 2014-10-18 11:19:51 · 2105 阅读 · 1 评论