![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
编程之美
happy曾帅
这个作者很懒,什么都没留下…
展开
-
寻找发帖水王(找出数组出现超过一半的数字)
#includeusing namespace std;void find(int A[],int length){int times=0;int i=0;int temp;for(;i{if(times==0){temp=A[i];times=1;}else{if(A[i]==temp)times++;elsetimes原创 2015-04-12 16:55:14 · 638 阅读 · 0 评论 -
3.9已知二叉树的 前序遍历和中序遍历的结果,重构出原二叉树
#includeusing namespace std;struct Node{ char value; Node *left; Node *right;};//重构函数核心Node *Constructcore(char *start_preorder,char *end_preorder,char *start_inorder,char *end_inorder){ ch原创 2015-04-28 10:21:05 · 787 阅读 · 2 评论 -
3.10分层打印二叉树的节点
#include#includeusing namespace std;struct Node{ char value; Node *left; Node *right;};void create(Node *&T){ char c; cin>>c; if('#'==c) { T=NULL; } else { T=new Node; T->value=原创 2015-04-28 10:52:20 · 561 阅读 · 0 评论 -
编程之美第三章-3.2-电话号码以及对应的单词
#include#includeusing namespace std;const int max_length=9;char c[10][10]={ "",//0 "",//1 "ABC",//2 "DEF",//3 "GHI",//4 "JKL",//5 "MNO",//6 "PQRS",//7 "TUV",//8 "WXYZ",//9};int total[原创 2015-05-08 14:22:45 · 636 阅读 · 0 评论 -
编程之美第三章-字符串移位包含的问题
#include#includeusing namespace std;bool find_str(string s1,string s2){ if(s1.empty()||s2.empty()) return false; string::size_type pos=s1.find(s2); return (pos!=string::npos)?true:false;}in原创 2015-05-08 14:07:28 · 485 阅读 · 0 评论 -
2.11寻找最近的点对 (给定一系列的点,求出距离最短的点对)
#include#include#includeusing namespace std;/*int pow(int a,int index){ int result=1; int temp=a; for(;index;index>>=1) { if(index&1) result*=temp; temp*=temp; } return result;}*/原创 2015-04-21 11:47:08 · 1441 阅读 · 0 评论 -
如何有效的实现一个正整数的N次方
以时间复杂度为logn来实现一个数的N次方;#includeusing namespace std;int pow(int a,int index){ int result=1; int temp=a; for(;index;index>>=1) { if(index&1) result*=temp; temp*=temp; } return result;}原创 2015-04-21 09:54:57 · 888 阅读 · 1 评论 -
程之美第3章结构之法-字符串及链表的探索3.7 队列中取最大值操作问题
#include#includeusing namespace std;class stack{private: vector vec;//用来保存当前进栈的值 vector max_vec;public: void push(int a) { vec.push_back(a); if(max_vec.size()==0||a>vec[max_vec[max_ve原创 2015-04-24 09:46:34 · 617 阅读 · 0 评论 -
编程之美中判断某个字符串是否是另一个字符串的移位结构的子串
#include#includeusing namespace std;bool is_circle(string src,string des){ if(src.empty()||des.empty()) return false; string temp=src; temp+=src; string::size_type pos=0; pos=temp.find(des)原创 2015-04-23 13:45:47 · 1270 阅读 · 0 评论 -
2.2阶乘中末尾0的个数
#includeusing namespace std;int count(int N){ if(N==0) return 0; int num=0; for(int i=1;i<=N;++i) { int j=i; while(j%5==0) { num++; j/=5; } } return num;}int aa(int N){ i原创 2015-04-12 16:02:55 · 586 阅读 · 0 评论 -
编程之美中1的个数的问题
//采用最直接的方法,时间复杂度为O(N*logN);/*#include #include#include#includeusing namespace std; int num_one(int n){ int count=0; while(n) { count+=(n%10==1)?1:0; n/=10; } return count;}int core原创 2015-05-18 10:32:39 · 1068 阅读 · 0 评论