int main(int argc, const char * argv[]) { // insert code here... int n; scanf("%d", &n); printf("%s\n", countAndSay(n)); return 0; }
int main(void){ int n = 7; char *s = countAndSay(n); printf("n: %d, s: %s\n", n, s); free(s); return 0; }
int main(int argc, char *argv[]) { countAndSay(5); return 0; }
string countAndSay(int n) { if (n < 1) return NULL; string result = "1"; for (int i = 2; i <= n; i++) result = countAndSay(result); return result; }
string countAndSay(int n) { if(n < 1) return string(); string res("1"); for(int i = 2;i <= n; ++i) res = countAndSay(res); return res; }
// ----------------------------------------------------------------------------- //virtual bool Solution::Test() { bool pass = true; pass = pass && (countAndSay(-1) == "1") && (countAndSay(0) == "1") && (countAndSay(1) == "1") && (countAndSay(2) == "11") && (countAndSay(3) == "21") && (countAndSay(4) == "1211") && (countAndSay(5) == "111221") && (countAndSay(6) == "312211") && (countAndSay(7) == "13112221") && (countAndSay(8) == "1113213211") ; return pass; }
void main(int argc, char** argv) { int n = 1; if (argc >= 2) n = atoi(argv[1]); char* say = countAndSay(n); printf("%s\n", say); free(say); }
int main(void){ int i; char *say; for(i=1;i<=30;i++){ say = countAndSay(i); printf("No%d\n%s\n\n",i,say); free(say); } return 0; }
string countAndSay(int n) { // IMPORTANT: Please reset any member data you declared, as // the same Solution instance will be reused for each test case. string str = "1"; int idx = 1; while(idx < n) { str = countAndSay(str); ++idx; } return str; }
int main(int argc,char **argv) { int n = 3; if(argc >1){ n = atoi(argv[1]); } char * ret = countAndSay(n); printf("ret = %s\n", ret); return 0; }
string countAndSay(int n) { if (n == 1) return "1"; string s = countAndSay(n - 1); string ans = ""; char p = s[0]; int c = 0; for (auto t:s) { if (t == p) c++; else { ans += to_string(c) + p; p = t; c = 1; } } ans += to_string(c) + p; return ans; }
void main(int argc, char * argv[]) { if (argc != 2) { printf("Please specify the correct arguments.\n"); return; } int n = atoi(argv[1]); int i = 1; char * s = NULL; for (; i<=n; ++i) { s = countAndSay(i); printf("%s\n", s); } free(s); }
/* * The count-and-say sequence is the sequence of integers beginning as follows: * 1, 11, 21, 1211, 111221, ... * 1 is read off as "one 1" or 11. * 11 is read off as "two 1s" or 21. * 21 is read off as "one 2, then one 1" or 1211. * Given an integer n, generate the nth sequence. * * Note: The sequence of integers will be represented as a string. */ char* countAndSay(int n) { switch (n) { case 1: return strdup("1"); case 2: return strdup("11"); case 3: return strdup("21"); case 4: return strdup("1211"); case 5: return strdup("111221"); default: if (n <= 0) { return NULL; } break; } char* t = countAndSay(n - 1); char* ret; int tlen = strlen(t); ret = (char*)malloc((tlen << 1) + 1); char* p; char* q; char* mark; int ch; int i; for (p = t, q = ret; (ch = *p) != 0;) { mark = p; while (ch == *(++p)); i = sprintf(q, "%d%c", (p - mark), ch); if (i < 0) { break; } q += i; } *q = '\0'; free(t); return ret; }
string countAndSay(int n) { string res; if(n==1) { res="1"; return res; } string s=countAndSay(n-1); int i=0; while(i<s.size()) { char num=s[i]; int cnt=1; while(s[i+1]==num) { cnt++; i++; } i++; res.push_back(cnt+'0'); res.push_back(num); } return res; }
int main(int argc, char *argv[]) { printf("%s\n", countAndSay(atoi(argv[1]))); return(0); }
string countAndSay(int n) { if (n == 1) return "1"; if (n == 2) return "11"; return say(countAndSay(n-1)); }
int main() { printf("%s\n", countAndSay(3)); return 0; }
void CountAndSay::TestClass() { cout<<"the result is="<<endl; cout<<countAndSay(111221)<<endl; }
void test() { cout << countAndSay(3) << endl; }
string countAndSay(int n) { if (n == 1) return "1"; return readStr(countAndSay(n - 1)); }