1.大数相乘
#include<iostream>
#include<cstdio>
#include<math.h>
using namespace std;
int multiply (const std::string sA,const std::string sB, std::string &res)
{
/* 在这里实现功能 */
string A = sA;
string B = sB;
int a = A.length();
int b = B.length();
int reslen = 0;
int c = (a+1)*(b+1);
int *p = new int[c];//逆序存放的结果
int *pA = new int[a];//逆序存放的乘数A
int *pB = new int[b];//逆序存放的乘数B
//测试是否有乘数为空
if ((a == 0) || (b == 0))
return -1;
for (int i = 0; i != c; i++)
p[i] = 0;
for (string::size_type index = 0; index != A.length(); index++)
pA[a-1-index] = A.at(index) - '0';
for (string::size_type index = 0; index != B.length(); index++)
pB[b-1-index] = B.at(index) - '0';
for (int temp_b = 0; temp_b != b; temp_b++)
{
for (int temp_a = 0; temp_a != a; temp_a++)
{
int temp = p[temp_a+temp_b] + pA[temp_a]*pB[temp_b];
p[temp_a+temp_b] = temp % 10;
int carry = temp/10;
int x = temp_a + temp_b +1;
while(carry != 0)//进位不等于0
{
p[x] = p[x] + carry%10;
carry = carry/10;
x++;
}
}
}
while (c-- > 0) //判断结果有几位
{
if (p[c] != 0)
{
reslen = c + 1;
break;
}
}
char ch;
for (int i = reslen - 1; i >= 0 ; i--) //把结果放入字符串中
{
ch = p[i] + '0';
res.push_back(ch);
}
if (res.empty())//如果结果为0,则输出字符串为“0”
{
res= "0";
}
return 0;
}
int main(void)
{
string sA;
cin>>sA;
string sB;
cin>>sB;
string res = "\0";
multiply (sA,sB,res);
cout <<res<<endl;
return 0;
}
2.面试经历:
一面:
1.自我介绍
2.介绍项目
3.写快排,插入排序
4.面试官介绍部门(感觉是做开发的,可是我面的算法工程师)
5.学了哪些课程
反正。。。不难。。。
二面:
1.本科和硕士学校的区别
2.介绍项目
3.闲聊。。。二面的面试官没怎么为难我,我室友面二面的时候被各种问题狂轰滥炸,什么优缺点,项目角色,项目难点什么的各种。
4.有什么想问的