筆試面試題目8

2021-06-18 23:24:43 字數 2624 閱讀 7363

1. 寫乙個 string類,以及建構函式能是虛函式嗎?

class string

string( char *str = null); // 建構函式

string( int len, char ch);

~string(); // 析構函式

string( string &str); // 複製建構函式

int size() // 獲得字串長度

string operator+(const string& str); // 過載'+'操作符

string& operator+=(const string& str); // 過載'+='操作符

string& operator=(const string& str); // 過載賦值操作符

bool operator==(const string &s1,const string &s2); // 比較兩個字串是否相等

char& operator( int index); // 過載下標操作符

string substr( int pos,int len); // 返回子字串

string substr( int pos); // 返回子字串

private:

char *m_pdata;

int m_length;

};string::string(char *str) // 建構函式

}string::string( int len, char ch);

m_pdata[len] = '\0';

}string::~string() // 析構函式

length = 0;

}string::string(string &str) // 複製建構函式

b[m_length] = '\0';

}string string::operator+(const string& str) // 過載+

for( int i =0; count < newlen; count++,i++)

newstr[newlen] = '\0';

string temp(newstr);

delete newstr;

return temp;

}string& string::operator+=(const string& str) // 過載+=

for(int i =0;countm_length)

return m_pdata[m_length-1];

else

return m_pdata[index];

}ostream& operator<<(ostream& os, string& str) //過載輸出符

istream& operator>>( std::istream& is, string& str) //過載輸入符

string string::substr( int pos, int len) // 兩個接受不同引數的substr函式,返回子字串

; int count = 0;

unsigned int tmp = num;

while( tmp > 0)

int max = 0;

int i = 0;

for( i = 0; i < count; i++)

else if(max > num[i] && i != 0)

}break;}}

sort(num, num+i, greater());

cout << num << " ---> ";

for( int i = count-1; i >= 0; i--)

cout << endl;

return ;

}int main()

5. 陣列逆時針旋轉90度,以及證明你的方法的有效性

1 2 3

3 6 9

4 5 6

--->  2 5 8

7 8 9

1 4 7

#include #include #include using namespace std;

#define array_len 3

int numarray[array_len][array_len];

void rotatearray()

}for( i = 0; i < array_len/2; i++)

}return ;

}int main()

}for( int i = 0; i < array_len; i++)

cout << endl;

}cout << "<------------->" << endl;

rotatearray();

for( int i = 0; i < array_len; i++)

cout << endl;

}return 0;

}

對於證明其正確性:

可以將整個矩陣放到座標軸上,乙個點代表其對應的座標值。

可以推導出相應的座標對應。

by andy @ 2023年11月1日

微軟筆試面試題目

智力題 1 燒一根不均勻的繩子,從頭燒到尾總共需要1個小時,問如何用燒繩子的方法來確定半小時的時間呢?2 10個海盜搶到了100顆寶石,每一顆都一樣大小且價值連城。他們決定這麼分 1 抽籤決定自己的號碼 1 10 2 首先,由1號提出分配方案,然後大家表決,當且僅當超過半數的人同意時,按照他的方案進...

筆試面試題目1

1.求重合段的長度 size t foo unsigned int a1,size t al1,unsigned int a2,size t al2 其中a1和a2都為無符號陣列,al1和al2為陣列的長度,陣列的長度為偶數。無符號陣列由一對數字區間組成。如下例 a1 為 0,1,3,6,10,20...

XX筆試面試題目

瀏覽器預設字型大小是16px 事件繫結addeeventlistener和普通繫結on的區別 把url的引數轉換成json物件 json物件和字串的相互轉換 事件委託的理解?canvas 判斷 不是非替換元素?能做動畫,也能響應事件?匹配div不含子元素 選項 div not null no emp...