1_2017年中興機試題

 

  剛剛作完機試html

個人題目git

.1 求得數字在一個整數中出現的次數數組

求得數字在一個整數中出現的次數,函數輸入兩個參數,一個是數字,一個是整數。示例輸入,函數

2,122334

示例輸出,spa

2

該題的重點在於如何將一個整數串分解爲單個的數字,好比將「122334」,分解爲1,2,2,3,3,4,而後再判斷數字出現的次數便可。.net

那麼如何分解呢?咱們慢慢來, 
首先,如何獲得個位數字呢,咱們能夠將122334取10的餘數,4,便是個位數; 
十位數呢?咱們將122334除以10,獲得12233,而後再取10的餘數,3,便是十位數; 
百位數?咱們將122334除以100,即12233除以10,而後再取10的餘數,3,便是百位數; 
。。。。依次下去, 
咱們能夠發現,若是咱們要求得某一位的數字,將整數除以10的某次方,再取10的餘數就能夠了。咱們能夠使用循環的方法依次求的當前數字,而後判斷,代碼以下,3d

 int findDigitOccurrence(int num1, int num2) {
        int left = 0;//餘數
        int num = 0;//當前數字
        while (num2 > 0) { left = num2 % 10; num2 = num2 / 10; if (num1 == left) { num++; } } return num; }

 

 2 旋轉矩陣指針

某個圖像經過一個整數組成的m*n矩陣表示,其中每一個整數表示一個像素值。寫出一種方法,根據flag變量的值將圖像向右或者向左旋轉90°。若是flag值爲0,則向左旋轉,若是flag爲1,則向右旋轉。code

函數rotatePictureMethod的輸入分別由矩陣matrix、矩陣的維度m和n以及flag的值組成。htm

函數應返回一個指向二維矩陣指針,該矩陣是按照flag值旋轉後的結果矩陣而動態分配的。

示例:

若是標誌flag=1且m=3,n=3,輸入矩陣

1   2   3

4   5   6

7   8   9

輸出矩陣

7   4   1

8   5   2

9   6   3

using namespace std;
int **rotatePictureMethod(int **matrix,int m,int n,int flag){ int **mat = new int *[n]; for(int i = 0;i<n;++i) { mat[i] = new int [m]; } if(flag == 1) { for(int i = 0;i<m;++i) { for(int j = 0;j<n;++j) { mat[n-1-j][m-1-i] = matrix[i][n-1-j]; } } } else{ for(int i = 0;i<m;++i){ for(int j = 0;j<n;++j){ mat[n-1-j][m-1-i] = matrix[m-1-i][j]; } } return mat; } //FUNCTION SIGNATURE ENDS

 

參考資料

1.http://blog.csdn.net/qq_21905401/article/details/52353668

2.http://www.cnblogs.com/coderli/p/f93ad2f8b0dd72aa5a997c766a6a95ac.html

3.http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed4fece7631046893b4c4380146d96864968d4e414c42246191c31bbe07b6157578f9e227a52ef0f07bbae616f615466e4c096c957dabb93282a8221346459db0144dc19adc84332c050872cedb86fe5ad863084dfa2c4de2444ba50120bf3e7fa291762cc&p=9b36c54ad5c144b71dbe9b7c4f5185&newp=882a9647d38433b946a9c7710f56c4231611d63f6fbada156b82c825d7331b001c3bbfb427211601d5cf7d6307a45d1a87b1613038547ce1dcba9e5499&user=baidu&fm=sc&query=2017%D6%D0%D0%CB%B1%CA%CA%D4&qid=f255a15e00014e86&p1=1

4.http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed4fece7631046893b4c4380146d96864968d4e414c42246064565e5b92d28100fd5d82f2747f41802bded602571507be9dad58f4adcba912d2a8330350442db10419542f2973a629e37912cedbb5cbafaa63d84d8d6c4a95644bc51120bf0e78a2a0016c96ae71541f4d09b5f665e07cceb2715fd4e7659885547a131fbf7436a10f1fcca5d3cd45ad37660e4b844c32964b3&p=b439c54ad3c91efc57efe60c5f55&newp=ce6a8e5e85cc43ff57e89e36420d92695803ed6636d2c44324b9d71fd325001c1b69e7ba27241000d0c5776001ac435ae1f33779361766dada9fca458ae7c4&user=baidu&fm=sc&query=%D6%D0%D0%CB2017%D0%A3%D4%B0%D5%D0%C6%B8%B1%CA%CA%D4&qid=dca0ca9a00014e74&p1=2

5.http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed4fece7631046893b4c4380146d96864968d4e414c42246041d21f4bc537a43558ad82f2747f41802bded602571507be9dad58f4adcb197292b8333712d5cd04e05a51db8bd4432b722872b99b81897baf23196b9d3a3c82450dd22766df1839c2c0603cb1fe76540f4d1995f152e07caed2716f44e075d885236&p=923d8315d9c945e80be29636110c&newp=8749dd1a97d912a05abd9b74095092695c02dc3351d4d7136b82c825d7331b001c3bbfb427211601d5cf7d6307a45d1a87b1613038547ce1&user=baidu&fm=sc&query=%D6%D0%D0%CB2017%B1%CA%CA%D4%CC%E2+%B2%A9%BF%CD&qid=e7ac902a000165a3&p1=1

6.http://cache.baiducontent.com/c?m=9d78d513d9d437ab4f9b96697b14c017694381133cd5d31068d5e35fe3674c30347192c830541613d2b56b1670b83e5cfdf04765470337c490dff83ecacae43c68c8793b2a5ac00305d26ab2d6167b9c75875a9eee42bbe9e732e4ff8f8cc854249b0f183b9da0d5075503cd1bf41f3be4a699181e5d13b8ed7525fe066029e87906e919&p=c0769a47998511a05bed9266595197&newp=c37a86019c8012a05abd9b7d0d1086231611d63f6cbada146b82c825d7331b001c3bbfb427211601d5cf7d6307a45d1a87b1613038547ce1&user=baidu&fm=sc&query=%D6%D0%D0%CB2017%B1%CA%CA%D4%CC%E2+%B2%A9%BF%CD&qid=e7ac902a000165a3&p1=4

7.http://cache.baiducontent.com/c?m=9d78d513d9d437ab4f9b96697b14c017694381133cd5d31068d5e35fe3674c30347192c830541613d2b56b1670b83e5cfdf04765470337c490dff83ecacae43c68c8793b2a5ac00305d26ab2d603608437902db8f349b9e7a57384aea582820b4e9b0e532dc0aed04742099e64f14767e3f29318170946bfed6336f80a7c229a7245b243aae4616500d2a7ca5c3b996c8f3f&p=8c71c916d9c133ea1cbd9b7d0f13c9&newp=ce6ad25685cc43ff57ee967b584786231611d63f6cbad31078c0c513fe200c01063dbee728221302d6c3766605a94248ac9d7725750c77ebcd&user=baidu&fm=sc&query=%D6%D0%D0%CB2017%B1%CA%CA%D4%CC%E2+%B2%A9%BF%CD&qid=e7ac902a000165a3&p1=6

相關文章
相關標籤/搜索