[曆年IT筆試題]2015年去哪網實習筆試題,it2015年

來源:互聯網
上載者:User

[曆年IT筆試題]2015年去哪網實習筆試題,it2015年


(1)跟LeetCode中的:[LeetCode]33.Search in Rotated Sorted Array一樣。

/*-----------------------------------------------------------*   日期:2014-01-15*   作者:SJF0115*   題目: 33.Search in Rotated Sorted Array*   來源:http://oj.leetcode.com/problems/search-in-rotated-sorted-array/*   結果:AC*   來源:LeetCode*   總結:---------------------------------------------------------------*/#include <iostream>#include <stdio.h>using namespace std;class Solution {public:    //二分尋找    int search(int A[], int n, int target) {        int start = 0,end = n-1;        int mid;        while(start <= end){            mid = (start + end) / 2;            if(A[mid] == target){                return mid;            }            //中間元素大於最左邊元素則左部分為有序數組            else if(A[mid] >= A[start]){                //目標位於左部分                if(target >= A[start] && target <= A[mid]){                    end = mid - 1;                }                //目標位於右部分                else{                    start = mid + 1;                }            }            //中間元素小於最右邊元素則右部分為有序數組            else{                //目標位於右部分                if(target <= A[end] && target >= A[mid]){                    start = mid + 1;                }                //目標位於左部分                else{                    end = mid - 1;                }            }        }        return -1;    }};int main() {    int result;    Solution solution;    int A[] = {3,1};    result = solution.search(A,2,1);    printf("Result:%d\n",result);    return 0;}

關於更多二分尋找問題:[經典面試題]二分尋找問題匯總

(2)

#include<string>    #include<iostream>    using namespace std;    string Decode(string str){        string result;        int size = str.size();        if(size <= 0){            return result;        }//if        // 重複元素區間        int start = 0,end = 0;        // 重複次數        int count = 0;        for(int i = 0;i < size;++i){            // 數字            if(str[i] >= '0' && str[i] <= '9'){                count = count * 10 + str[i] - '0';                if(i == size || (str[i+1] < '0' || str[i+1] > '9')){                    for(int j = 0;j < count;++j){                        result += str.substr(start,end-start);                    }//for                    // 重新設定                    start = i + 1;                    end = i + 1;                    count = 0;                }//if            }//if            // 字元            else{                ++end;            }        }//for        return result;    }    int main(){        string str("love2big2gae4fff1");        cout<<Decode(str)<<endl;        return 0;    }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.