摘要: #include<iostream>#include<sstream>using namespace std;int main(){ string str1,str2; char *p1,*p2; int min; cout<<"请输入两个字符串:"; cin>>str1>>str2; p1=&st 阅读全文
posted @ 2013-05-14 22:35 herizai 阅读(526) 评论(0) 推荐(0) 编辑
摘要: #include <iostream>using namespace std; class A{};class B{public: operator A()//重载操作符,这个是操作符,从B 类型 转为A类型,{ return A(); }}; void func(A){ cout<<"this is from func"<<endl;}void main(){ B b; func(b);}class B{double a;public:operator double(){return a;}}int main(){B b;double 阅读全文
posted @ 2013-05-14 22:03 herizai 阅读(111) 评论(0) 推荐(0) 编辑
摘要: #include<iostream>#include<iomanip>using namespace std;int a[3][3];//声明二维数组void print();void change(int (*a)[3]);//参数为指针数组int main(){ cout<<"请输入一个3*3的矩阵"<<'\n'; for(int i=0;i<3;++i) for(int j=0;j<3;++j) { cin>>a[i][j]; } cout<<"写成3*3形式 阅读全文
posted @ 2013-05-14 22:00 herizai 阅读(153) 评论(0) 推荐(0) 编辑
摘要: #include "kmp.h"//一般的kmp算法求模式串匹配的位置,返回值下标从1开始计算intkmp(conststring&s,conststring&t){inti(0),j(0);int*next=newint;GetNext(t,next);//思想同求next类似while(i<s.length()&&j<(int)t.length())//此处注意,t.length()返回的是无符型,而j=-1{if(j==-1||s[i]==t[j]){i++;j++;}else{j=next[j];}}deletenext; 阅读全文
posted @ 2013-05-14 21:26 herizai 阅读(207) 评论(0) 推荐(0) 编辑
摘要: #include<iostream>#include<sstream>using namespace std;int main(){ int n; char *months[12]= { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October&quo 阅读全文
posted @ 2013-05-14 21:17 herizai 阅读(126) 评论(0) 推荐(0) 编辑
摘要: #include <iostream>using namespace std;int main(){ char a[50],b[50]; int i; for(i=0;i<50;i++) cin>>a[i]; int cnt_index=0,cnt_int=0; //cnt_int 用于存放字符串中的数字. //cnt_index 作为字符串b的下标. for(i=0;a[i]!='\0';++i) //当a数组元素不为结束符时.遍历字符串a.//遍历的一种方法 { if(a[i]>='0'&& a[i]< 阅读全文
posted @ 2013-05-14 21:05 herizai 阅读(255) 评论(0) 推荐(0) 编辑
摘要: 写出如下程序运行结果:#include<stdio.h>#include<string.h>intmain(){inta[2000];char*p=(char*)a;for(inti=0;i<2000;i++)a[i]=-1-i;printf("%d\n",strlen(p));return0;}请不要运行,先用草稿纸算算,能算出来不? 此乃网速科技2011校园招聘笔试题第一题,本人心里素质很不错,不过看到此题当时就懵了,哪有人这么写代码的,所以当时也没有做出来,后来运行以后也没有搞懂,刚刚吃饭,突然就明白了,特此记录、分享之。废话不多说,运行 阅读全文
posted @ 2013-05-14 20:13 herizai 阅读(149) 评论(0) 推荐(0) 编辑
摘要: #include<iostream>using namespace std;void change(int **pointer,int n);//声明int main(){ int n,**p2; cout<<"请输入整数的个数n="; cin>>n; int *a=new int(n);//动态分配 cout<<"请输入:"; for(int i=0;i<n;++i) cin>>a[i];//存储 p2=&a; change(p2,n);//调用 cout<<&quo 阅读全文
posted @ 2013-05-14 20:12 herizai 阅读(185) 评论(0) 推荐(0) 编辑
摘要: #include<iostream>structLIST{inta;LIST*back;};intmain(){intn;scanf("%d",&n);LIST*list=newLIST[n];//显示开辟了n个LIST结点for(inti=0;i<n;i++){list[i].a=i+1;//这是为第i个(从0数)LIST结点的数据域a赋值if(i!=n-1)//出于这个判断是为了形成一个环形链表,在i不等于n-1(也就是不是最后一个)的时候list[i].back=&list[i+1];//都是把list数组中的后一个元素(这里指的是L 阅读全文
posted @ 2013-05-14 19:16 herizai 阅读(164) 评论(0) 推荐(0) 编辑
摘要: #include<iostream>#include<sstream>using namespace std;int main(){ void compare(string *a); string a[3]; cout<<"请输入需比较的三个字符串:"; for(int i=0;i<3;++i) cin>>a[i]; compare(a); cout<<"从小到大排序为:"; for(i=0;i<3;++i) cout<<a[i]<<" " 阅读全文
posted @ 2013-05-14 18:35 herizai 阅读(158) 评论(0) 推荐(0) 编辑