Posts

Showing posts from February, 2014

[ITint5] Excel Number

http://www.itint5.com/oj/#23 The row and column indices in Excel are denoted by: A, B, C, ..., Z, AA, AB, ... AZ, BA, ... The corresponding decimal numbers are: 1, 2, 3, ..., 26, 27, 28, ... Implement two functions to transform decimal numbers to Excel numbers and vice versa. Excel number is a numeral system based 26.

Wildcard Matching

Implement wildcard pattern matching with support for '?' and '*'.  '?' Matches any single character.  '*' Matches any sequence of characters (including the empty sequence).  The matching should cover the entire input string (not partial).  The function prototype should be: bool isMatch(const char *s, const char *p)  Some examples:  isMatch("aa","a") → false  isMatch("aa","aa") → true  isMatch("aaa","aa") → false  isMatch("aa", "*") → true  isMatch("aa", "a*") → true  isMatch("ab", "?*") → true  isMatch("aab", "c*a*b") → false Use two pointers to save the position of last '*' and the position of corresponding char in s. First time when we meet '*', we assume it is an empty string. Once we do not find the match, backtrack to the last '*', and assume it matches a string of length

Regular Expression Matching

Implement regular expression matching with support for '.' and '*'. '.' Matches any single character. '*' Matches zero or more of the preceding element. The matching should cover the entire input string (not partial). The function prototype should be: bool isMatch(const char *s, const char *p) Some examples: isMatch("aa","a") → false isMatch("aa","aa") → true isMatch("aaa","aa") → false isMatch("aa", "a*") → true isMatch("aa", ".*") → true isMatch("ab", ".*") → true isMatch("aab", "c*a*b") → true If the next character of p is not *: check current *s and *p, and recursive search. If the next character of p is *: search all possibilities.