Tuesday, August 4, 2009

Give me a function that given a line, describes the next

1
11
21
1211
111221
312211
13112221
1113213211


char* get_next_line(char* line)
{
char next_line[4096];
int next_line_ndx = 0;

char letter = line[0];
int num_letters = 0;

for (int i = 0; i < strlen(line); ++i)
{
if (letter != line[i+1])
{
next_line[next_line_ndx] = num_letters + '0';
next_line_ndx++;
next_line[next_line_ndx] = letter;
next_line_ndx++;
next_line[next_line_ndx] = 0;

letter = line[i+1];
num_letters = 0;
}
else
{
num_letters++;
}
}

return next_line;
}

5 comments:

Anonymous said...

hello........................................

Anonymous said...

留言是種美德-感謝分享 ....................................................

Anonymous said...

你可以從外表的美來評論一朵花或一隻蝴蝶,但你不能這樣來評論一個人........................................

Anonymous said...

成功等於目前,其他都是這句話的註解。........................................

Anonymous said...

haha~ funny! thank you for your share~ ........................................