[IT pen questions over the years] Which Online internship pen questions will I go to in 2015, it 2015

Source: Internet
Author: User

[IT pen questions over the years] Which Online internship pen questions will I go to in 2015, it 2015


(1) Same as [LeetCode] 33. Search in Rotated Sorted Array in LeetCode.

/* ----------------------------------------------------------- * Date: * Author: SJF0115 * Subject: 33. search in Rotated Sorted Array * Source: output result: AC * Source: LeetCode * Summary: ----------------------------------------------------------- */# include <iostream> # include <stdio. h> using namespace std; class Solution {public: // Binary search 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 ;} // if the middle element is greater than the leftmost element, the left part is divided into an ordered array else if (A [mid]> = A [start]). {// the target is located in the left part. if (target> = A [start] & target <= A [mid]) {end = mid-1 ;} // The target is in the right else {start = mid + 1 ;}} // if the middle element is smaller than the rightmost element, the right part is divided into the ordered array else {// the target is located in the right part 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 ;}

For more questions about Binary Search: [classic Interview Questions] problem summary about Binary Search

(2)

# Include <string ># include <iostream> using namespace std; string Decode (string str) {string result; int size = str. size (); if (size <= 0) {return result;} // if // The repeating element interval int start = 0, end = 0; // number of repetitions int count = 0; for (int I = 0; I <size; ++ I) {// number 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 // reset start = I + 1; end = I + 1; count = 0 ;} // if} // if // character else {+ end ;}// for return result;} int main () {string str ("love2big2gae4fff1 "); cout <Decode (str) <endl; return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.