C/C++程序员面试宝典-2
来源:互联网 发布:mac图片浏览器 编辑:程序博客网 时间:2024/05/16 02:07
9. 关系数据库的范式
10. 数据库操作中的事务
事务的4个特性:
11. 数字矩阵的生成:
对应的代码如下:
#include <iostream>
#include <algorithm>
#include <iomanip>
#define print_arr2d(arr,N) {for(int i=0;i<N;i++){\
for(int j=0;j<N;j++)\
cout<<setw(3)<<arr[i][j];\
cout<<endl;\
}}
using namespace std;
/*
1 2 9 10 25
4 3 8 11 24
5 6 7 12 23
16 15 14 13 22
17 18 19 20 21
*/
void mat_1(){
const int N=5;
int arr[N][N];
int m=1;
for(int i=0;i<N;i++){
if(i&0x1){
for(int j=0;j<=i;j++)
arr[j][i]=m++;
for(int j=i-1;j>=0;j--)
arr[i][j]=m++;
}
else{
for(int j=0;j<=i;j++)
arr[i][j]=m++;
for(int j=i-1;j>=0;j--)
arr[j][i]=m++;
}
}
print_arr2d(arr,N);
}
/*
1 2 6 7 15
3 5 8 14 16
4 9 13 17 22
10 12 18 21 23
11 19 20 24 25
*/
void mat_2(){
const int N=5;
int a[N][N];
int m=1;
int K=0;
for(int i=0;i<N;i++,K++){
for(int j=0;j<=i;j++)
if(K%2==0)
a[K-j][j]=m++;
else
a[j][K-j]=m++;
}
for(int i=1;i<N;i++,K++){
for(int j=i;j<N;j++)
if(K%2==0)
a[K-j][j]=m++;
else
a[j][K-j]=m++;
}
print_arr2d(a,N);
}
/*
1 2 3 4 5
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9
*/
void mat_3(){
const int N=6;
int a[N][N]={0};
int m=1;
int K=N/2;
if(N%2!=0)
a[K][K]=N*N;
for(int i=0;i<K;i++) {
for(int j=i;j<=N-1-i;j++)
a[i][j]=m++;
print_arr2d(a,N);
cout<<"================="<<endl;
for(int j=i+1;j<=N-1-i;j++)
a[j][N-1-i]=m++;
print_arr2d(a,N);
cout<<"================="<<endl;
for(int j=N-2-i;j>=i;j--)
a[N-1-i][j]=m++;
print_arr2d(a,N);
cout<<"================="<<endl;
for(int j=N-2-i;j>=i+1;j--)
a[j][i]=m++;
print_arr2d(a,N);
cout<<"================="<<endl;
}
print_arr2d(a,N);
}
/*
13 12 11 10 25
14 3 2 9 24
15 4 1 8 23
16 5 6 7 22
17 18 19 20 21
*/
void mat_4(){
const int N=6;
int a[N][N]={0};
int m=N*N;
int K=N/2;
if(N%2!=0)
a[K][K]=1;
for(int i=0;i<K;i++){
for(int j=i;j<=N-1-i;j++)
a[j][N-1-i]=m--;
for(int j=N-2-i;j>=i;j--)
a[N-1-i][j]=m--;
for(int j=N-2-i;j>=i;j--)
a[j][i]=m--;
for(int j=i+1;j<=N-2-i;j++)
a[i][j]=m--;
}
print_arr2d(a,N);
}
int main(){
mat_4();
}
#include <algorithm>
#include <iomanip>
#define print_arr2d(arr,N) {for(int i=0;i<N;i++){\
for(int j=0;j<N;j++)\
cout<<setw(3)<<arr[i][j];\
cout<<endl;\
}}
using namespace std;
/*
1 2 9 10 25
4 3 8 11 24
5 6 7 12 23
16 15 14 13 22
17 18 19 20 21
*/
void mat_1(){
const int N=5;
int arr[N][N];
int m=1;
for(int i=0;i<N;i++){
if(i&0x1){
for(int j=0;j<=i;j++)
arr[j][i]=m++;
for(int j=i-1;j>=0;j--)
arr[i][j]=m++;
}
else{
for(int j=0;j<=i;j++)
arr[i][j]=m++;
for(int j=i-1;j>=0;j--)
arr[j][i]=m++;
}
}
print_arr2d(arr,N);
}
/*
1 2 6 7 15
3 5 8 14 16
4 9 13 17 22
10 12 18 21 23
11 19 20 24 25
*/
void mat_2(){
const int N=5;
int a[N][N];
int m=1;
int K=0;
for(int i=0;i<N;i++,K++){
for(int j=0;j<=i;j++)
if(K%2==0)
a[K-j][j]=m++;
else
a[j][K-j]=m++;
}
for(int i=1;i<N;i++,K++){
for(int j=i;j<N;j++)
if(K%2==0)
a[K-j][j]=m++;
else
a[j][K-j]=m++;
}
print_arr2d(a,N);
}
/*
1 2 3 4 5
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9
*/
void mat_3(){
const int N=6;
int a[N][N]={0};
int m=1;
int K=N/2;
if(N%2!=0)
a[K][K]=N*N;
for(int i=0;i<K;i++) {
for(int j=i;j<=N-1-i;j++)
a[i][j]=m++;
print_arr2d(a,N);
cout<<"================="<<endl;
for(int j=i+1;j<=N-1-i;j++)
a[j][N-1-i]=m++;
print_arr2d(a,N);
cout<<"================="<<endl;
for(int j=N-2-i;j>=i;j--)
a[N-1-i][j]=m++;
print_arr2d(a,N);
cout<<"================="<<endl;
for(int j=N-2-i;j>=i+1;j--)
a[j][i]=m++;
print_arr2d(a,N);
cout<<"================="<<endl;
}
print_arr2d(a,N);
}
/*
13 12 11 10 25
14 3 2 9 24
15 4 1 8 23
16 5 6 7 22
17 18 19 20 21
*/
void mat_4(){
const int N=6;
int a[N][N]={0};
int m=N*N;
int K=N/2;
if(N%2!=0)
a[K][K]=1;
for(int i=0;i<K;i++){
for(int j=i;j<=N-1-i;j++)
a[j][N-1-i]=m--;
for(int j=N-2-i;j>=i;j--)
a[N-1-i][j]=m--;
for(int j=N-2-i;j>=i;j--)
a[j][i]=m--;
for(int j=i+1;j<=N-2-i;j++)
a[i][j]=m--;
}
print_arr2d(a,N);
}
int main(){
mat_4();
}
12. 大数乘法问题:
#include <string>
#include <iostream>
using namespace std;
string big_multi(const string& x,
const string& y){
int szx=x.size();
int szy=y.size();
int *C=new int[szx+szy+1]();
for(int i=szx-1,k=0;i>=0;i--,k++){
int carry=0;
int m=k;
for(int j=szy-1;j>=0;j--,m++){
int val=(x[i]-'0')*(y[j]-'0')+carry+C[m];
C[m]=val%10;
carry=val/10;
}
if(carry!=0)
C[m]=carry;
}
string z;
int i=szx+szy;
while(C[i]==0)
i--;
for(;i>=0;i--)
z+=(char)(C[i]+'0');
delete C;
return z;
}
int main(){
int a=78,b=42;
string x="78",y="42";
string z=big_multi(x,y);
cout<<z<<" "<<a*b<<endl;
}
#include <iostream>
using namespace std;
string big_multi(const string& x,
const string& y){
int szx=x.size();
int szy=y.size();
int *C=new int[szx+szy+1]();
for(int i=szx-1,k=0;i>=0;i--,k++){
int carry=0;
int m=k;
for(int j=szy-1;j>=0;j--,m++){
int val=(x[i]-'0')*(y[j]-'0')+carry+C[m];
C[m]=val%10;
carry=val/10;
}
if(carry!=0)
C[m]=carry;
}
string z;
int i=szx+szy;
while(C[i]==0)
i--;
for(;i>=0;i--)
z+=(char)(C[i]+'0');
delete C;
return z;
}
int main(){
int a=78,b=42;
string x="78",y="42";
string z=big_multi(x,y);
cout<<z<<" "<<a*b<<endl;
}
13. 递归的方法将两个有序链表进行合并
0 0
- C/C++程序员面试宝典-2
- JAVA程序员面试宝典C
- JAVA程序员面试宝典C收藏
- C/C++程序员面试宝典-1
- 3.c/c++程序员面试宝典-变量
- 4.c/c++程序员面试宝典-引用
- 9.c/c++程序员面试宝典-递归
- 22.c/c++程序员面试宝典-类
- 24.c/c++程序员面试宝典-多态
- 25.c/c++程序员面试宝典-继承
- 34.c/c++程序员面试宝典-模板
- 35.c/c++程序员面试宝典-容器
- 36.c/c++程序员面试宝典-表
- C/C++程序员面试宝典备忘录
- 《程序员面试笔试宝典》C知识归纳
- c++/c面试宝典
- C语言面试宝典
- C语言面试宝典
- 发布有礼!2015 Autodesk程序商店有奖发布活动拉开序幕
- ./demoCA/newcerts: No such file or directory
- python3 编码问题
- 3.仿微信--注册界面 补充用到的类
- 第三周项目1-顺序表的基本运算(1)
- C/C++程序员面试宝典-2
- 项目0-宣示主权
- MAC地址批量生成器
- 项目1-顺序表的基本算法
- 第2周时间项目3-体验复杂度(2)汉诺塔
- MarkDown学习
- 第三周项目(2):顺序表的基本运算
- shell
- vs2010文件加载使用简体中文(GB2312)问题解决方案