Counting substring that begin with character 'A' and ends with character 'X'
问题 PYTHON QN: Using just one loop, how do I devise an algorithm that counts the number of substrings that begin with character A and ends with character X ? For example, given the input string CAXAAYXZA there are four substrings that begin with A and ends with X , namely: AX , AXAAYX , AAYX , and AYX . For example: >>>count_substring('CAXAAYXZA') 4 回答1: Since you didn't specify a language, im doing c++ish int count_substring(string s) { int inc = 0; int substring_count = 0; for(int i = 0;i < s