Index Sort
/************************************************************************/ /* given an array of integer, write a method to find indices m and n such that if you sorted elements m through n, the entire array would be sorted. Minimize n-m that is find the smallest such sequence eg. input: 1,2,4,7,10,11,12,7,12,6,7,16,18,19 output: (3,10)*/ /* basic idea: using two stacks to remember the numbers, one is from head and the other is from the tail. */ /************************************************************************/ #include <iostream> #include <stack> using namespace std; int getindiceFhead( int a[], int length); int getindiceFtail( int a[], int length); void getIndices( int a[], int length) { int m, n; m = getindiceFhead(a, length); n = getindiceFtail(a, length) - m; cout<< "(" <<m<< ", " <...
declare a list
ReplyDeletelist = []
declare a dictionary
dic = {}
Regular Expressions in Python
ReplyDeleteAn example regex is r"^(From|To|Cc).*?python-list@python.org"
- the caret ^ matches text at the beginning of a line.
- the part with (From|To|Cc) means that the line has to start with one of the words that are separated by the pipe |
- The .*? means to un-greedily match any number of characters, except the newline \n character. The un-greedy part means to match as few repetitions as possible. The . character means any non-newline character, the * means to repeat 0 or more times, and the ? character makes it un-greedy.