日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Google2012.9.24校园招聘会笔试题

發布時間:2024/7/19 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Google2012.9.24校园招聘会笔试题 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.





代碼:

//轉載請標明出處,原文地址:http://blog.csdn.net/hackbuteer1/article/details/8017703 bool IsPrime(int n) {int i;if(n < 2)return false;else if(2 == n)return true;if((n&1) == 0) //n%2 == 0return false;for(i = 3 ; i*i <= n ; i += 2) //只考慮奇數{if(n % i == 0)return false;}return true; }/* 考慮到所有大于4的質數,被6除的余數只能是1或者5 比如接下來的5,7,11,13,17,19都滿足所以,我們可以特殊化先判斷2和3 但后面的問題就出現了,因為并非簡單的遞增,從5開始是+2,+4,+2,+4,....這樣遞增的 這樣的話,循環應該怎么寫呢?首先,我們定義一個步長變量step,循環大概是這樣 for (i = 5; i <= s; i += step) 那么,就是每次循環,讓step從2變4,或者從4變2 于是,可以這么寫: */ bool IsPrime2(int n) {int i, step = 4;if(n < 2)return false;else if(2 == n || 3 == n)return true;if((n&1) == 0) //n%2 == 0return false;if(n%3 == 0) //n%3 == 0return false;for(i = 5 ; i*i <= n ; i += step){if(n % i == 0)return false;step ^= 6;}return true; }void print_prime(int n) {int i , num = 0;for(i = 0 ; ; ++i){if(IsPrime2(i)){printf("%d " , i);++num;if(num == n)break;}}printf("\n"); }

代碼:

//轉載請標明出處,原文地址:http://blog.csdn.net/hackbuteer1/article/details/8017703 void myswap(int a , int b , int* array) {int temp = array[a];array[a] = array[b];array[b] = temp; }//利用0和其它數交換位置進行排序 void swap_sort(int* array , int len) {int i , j;for(i = 0 ; i < len ; ++i) //因為只能交換0和其他數,所以先把0找出來{if(0 == array[i]){if(i) //如果元素0不再數組的第一個位置myswap(0 , i , array);break;}}for(i = 1 ; i < len ; ++i) //因為是0至N-1的數,所以N就放在第N的位置處{if(i != array[i]) //這個很重要,如果i剛好在i處,就不用交換了,否則會出錯{for(j = i + 1 ; j < len ; ++j){if(i == array[j]){myswap(0 , j , array); //把0換到j處,此時j處是0myswap(j , i , array); //把j處的0換到i處,此時i處是0myswap(0 , i , array); //把i處的0換到0處}}//for}}//for }


代碼:
//轉載請標明出處,原文地址:http://blog.csdn.net/hackbuteer1/article/details/8017703 int mymin(int a , int b , int c) {int temp = (a < b ? a : b);return temp < c ? temp : c; }int min_edit_dic(char* source , char* target) {int i , j , edit , ans;int lena , lenb;lena = strlen(source);lenb = strlen(target);int** distance = new int*[lena + 1];for(i = 0 ; i < lena + 1 ; ++i)distance[i] = new int[lenb + 1];distance[0][0] = 0;for(i = 1 ; i < lena + 1 ; ++i)distance[i][0] = i;for(j = 1 ; j < lenb + 1 ; ++j)distance[0][j] = j;for(i = 1 ; i < lena + 1 ; ++i){for(j = 1 ; j < lenb + 1 ; ++j){if(source[i - 1] == target[j - 1])edit = 0;elseedit = 1;distance[i][j] = mymin(distance[i - 1][j] + 1 , distance[i][j - 1] + 1 , distance[i - 1][j - 1] + edit);//distance[i - 1][j] + 1 插入字符//distance[i][j - 1] + 1 刪除字符//distance[i - 1][j - 1] + edit 是否需要替換}}ans = distance[lena][lenb];for(i = 0 ; i < lena + 1 ; ++i)delete[] distance[i];delete[] distance;return ans; }



總結

以上是生活随笔為你收集整理的Google2012.9.24校园招聘会笔试题的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。