笔试题随想
近来找实习,在某公司的笔试上做了这么一到题目:
请写一个reserved()函数,函数原型自定,功能为反向输出字符串。例:输入:abc,输出cba
代码
#include <string>
#include <iostream>
#include <Windows.h>
using namespace std;
char * reserve( const char* p, int length)
{
char* ch = new char[length+1];
for( int i = length -1,k = 0 ; i >= 0; i--)
{
ch[k] = p[i];
k++;
}
ch[length] = '\0';
return ch;
}
void main()
{
string temp = "hello world!";
const char* temp2 = temp.data();
char * reserveValue = reserve( temp2, temp.length());
cout<<reserveValue;
delete reserveValue;
reserveValue = 0;
Sleep(5000);
}
上述代码原创,回想当时犯了很多错误,没有delete指针,没有把指针赋值为NULL等
还有一题是:
给定char p[] = "2330654889832109380175640953905",char q[] = "323423467080594281103066234234781821000505",
写一个加法函数,实现大数的加法运算。
目前在研究中。

浙公网安备 33010602011771号