count and say
string countAndSay(int n) { // Start typing your C/C++ solution below // DO NOT write int main() function string s = "1"; while( n>1 ) { string t=""; int i = 0; while( i < s.length() ) { int count = 1; while(i+1<s.length() && s[i+1]==s[i] ) { count++; i++; } char m = count + '0' ; t = t + m; t = t + s[i]; i ++; } s = t; n--; } return s; }
posted on 2013-07-03 19:59 jumping_grass 阅读(128) 评论(0) 收藏 举报
浙公网安备 33010602011771号