c++面试题整理(四)
2012-05-20 22:29
211 查看
43. 分析一下这段程序的输出 (Autodesk)
运行结果为:
![](http://my.csdn.net/uploads/201205/20/1337524766_3952.jpg)
44.写一个函数找出一个整数数组中,第二大的数 (microsoft)
![](http://static.blog.csdn.net/xheditor/xheditor_emot/default/laugh.gif)
44.写一个在一个字符串(n)中寻找一个子串(m)第一个位置的函数。
KMP算法效率最好,时间复杂度是O(n+m),
#include<iostream> using namespace std; class B{ public: B(){ cout<<"default constructor"<<endl; } ~B(){ cout<<"destructed"<<endl; } B(const B& b){ data=b.data; cout<<"copy constructor"<<endl; } const B& operator=(const B& b) { if(this!=&b) { data=b.data; cout<<"operator="<<endl; } return *this; } B(int i):data(i) { cout<<"constructed by parameter"<<data<<endl; } private: int data; }; B Play( B b) { return b; } int main(int argc, char* argv[]) { B t1; t1=Play(5); //t1=t1; B t2=Play(t1); return 0; }
运行结果为:
![](http://my.csdn.net/uploads/201205/20/1337524766_3952.jpg)
44.写一个函数找出一个整数数组中,第二大的数 (microsoft)
![](http://static.blog.csdn.net/xheditor/xheditor_emot/default/laugh.gif)
#include<iostream> using namespace std; int main(int argc, char* argv[]) { int a[]={1,6,5,6,7,9,3,4,10,18,9}; int size_a=sizeof(a)/sizeof(int); int first=a[0]; int second=a[0]; for(int i=1;i!=size_a;i++) { if(a[i]>first) { second=first; first=a[i]; } if(a[i]>second && a[i]<first) second=a[i]; } cout<<first<<'\t'<<second<<endl; return 0; }
44.写一个在一个字符串(n)中寻找一个子串(m)第一个位置的函数。
KMP算法效率最好,时间复杂度是O(n+m),
相关文章推荐
- 全面整理C++面试题
- 近期出现的C++面试题整理(附详细答案)
- 全面整理的C++笔试面试题
- [分类整理I]微软等100题系列V0.1版:c/c++基础面试题集锦
- 微软等100题系列V1.0版整理I:c/c++基础面试题集锦
- C++面试题整理
- 全面整理的C++面试题(转载)
- 全面整理的C++面试题
- 全面整理的C++面试题(转载)
- 面试题整理-C++ 序列化对象
- 全面整理的C++面试题
- [分类整理I]微软等100题系列V0.1版:c/c++基础面试题集锦
- 全面整理的C++面试题
- C++面试题( 收集并整理)
- [分类整理I]微软等100题系列V0.1版:c/c++基础面试题集锦
- 全面整理的C++面试题
- 全面整理的C++面试题
- C++笔试面试题 从网上整理的,带答案
- 全面整理的C++面试题
- 全面整理的C++面试题