摘要: 先帖段代码class A{public: virtual void f1(){puts("A");} virtual void f2(){f1();}};class B:public A{public : void f1(){puts("B");} void f2(){f1();}};class C:public A{public: void f1(){puts("C");}};int _tmain(int argc, _TCHAR* argv[]){ A a; B b; C c; a.f2(); b.f2(); c.f2(); pr 阅读全文
posted @ 2013-11-20 14:10 IT_cnblogs 阅读(188) 评论(0) 推荐(0) 编辑
摘要: 要求:读取一段字符串中的括号,检测括号的左右括号是否匹配,同时还要优先级也要匹配,如小括号内如果有中括号就属于优先级不匹配// project1.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include#includeusing namespace std;int priority(char bracket){ switch(bracket){ case '(': return 1; case '[': return 2; c 阅读全文
posted @ 2013-11-20 14:09 IT_cnblogs 阅读(1565) 评论(0) 推荐(0) 编辑
摘要: 先帖段代码,再慢慢分析吧// project1.cpp : Defines the entry point for the console application.//#include "stdafx.h"#includestruct A{ A(){puts("A()");};//默认构造函数 A(int v){puts("A(int)");};//重载构造函数 A(const A&){puts("A(A&)");};//拷贝或复制构造函数 A& operator=(const A & 阅读全文
posted @ 2013-11-20 14:08 IT_cnblogs 阅读(142) 评论(0) 推荐(0) 编辑
摘要: 没什么好说的,采用分治法,算法复杂度O(nlgn),帖个代码先// project1.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include#define LENGTH 100//合并//str[beg..mid]和str[mid+1..end]已有序//现str[beg..end]合并成有序,使用辅助数组assistint merge(char* str,char* assist,int beg,int mid,int end){ int reverse 阅读全文
posted @ 2013-11-20 14:07 IT_cnblogs 阅读(639) 评论(0) 推荐(0) 编辑
摘要: 还是直接贴代码// project1.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include#include#include#include#define LENGTH 1000using namespace std;int priority(char op){ switch(op){ case '(': return 0; case '+': case '-': return 1; case '*& 阅读全文
posted @ 2013-11-20 14:06 IT_cnblogs 阅读(209) 评论(0) 推荐(0) 编辑
摘要: 说明:有一条语句,如"Life is painting a picture, not doing a sum",要求语句中的单词左右对换,但每个单词不变,即变换后的串应该为"sum a doing not, picture a painting is Life"两种方法:1.分治法,将字符串变成一个单词和一个新的字符串然后对换,递归处理字符串。2.先整体反转,再每个单词反转,类似数组右移K位的方法// project1.cpp : Defines the entry point for the console application.//#include 阅读全文
posted @ 2013-11-20 14:05 IT_cnblogs 阅读(576) 评论(0) 推荐(0) 编辑
摘要: 说明:最大不重复串Longest not repeat string,简称LNRS,即在一个字符串中寻找连续的,没有重复字符的最长子串如"banana",LNRS为"ban"本文实现方法均是在别人的基础上,由本人实现,在此非常感谢大家的无私分享。方法1::暴力查找法,复杂度O(N^2)方法2:由于暴力查找时会有重复查找,所以使用动态规划法提高效率方法3:针对方法2进行空间优化方法4:动态规划+hash法// project1.cpp : Defines the entry point for the console application.//#incl 阅读全文
posted @ 2013-11-20 14:04 IT_cnblogs 阅读(345) 评论(0) 推荐(0) 编辑
摘要: 说明:最大重复子串Longest repeat string,简称LRS,即在一个字符串中寻找最长的重复子串例如"banana",则最大重复子串为"ana"三种方法方法1:暴力搜索法,复杂度O(N^2)方法2:使用后缀数组的方法方法3:利用KMP方法中的next数组同时补充了个KMP的代码,与本题无关// project1.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include#include#define LENG 阅读全文
posted @ 2013-11-20 14:03 IT_cnblogs 阅读(682) 评论(0) 推荐(0) 编辑
摘要: 参考网上的实现// project1.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include#define LENGTH 100//两个字符串的编辑距离//编辑距离就是将两个字符串变成相同字符串所需要的最小操作次数//纯暴力搜索法,复杂度O(N*M)int calEditDist(char strX[],int begX,int endX,char *strY,int begY,int endY){ if(endX==0){ if(endY==0) ... 阅读全文
posted @ 2013-11-20 14:02 IT_cnblogs 阅读(307) 评论(0) 推荐(0) 编辑
摘要: 先帖个代码// project1.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include#define LENGTH 1000//最大回文串,动态规划法:对暴力搜索的改进//暴力搜索O(N^2)个子串,每次O(N),总开销O(N^3)//通过动态规划法复杂度可以降到O(N^2)int LPS_dp(char *str){ int len=strlen(str); bool dp[LENGTH][LENGTH];//dp[i][j]记录子串[i..j]是否回 阅读全文
posted @ 2013-11-20 14:01 IT_cnblogs 阅读(278) 评论(0) 推荐(0) 编辑