smartbeast
BAN USERint do_count_coin(int *a, int sx, int sy, int x, int y)
{
int max_coin;
int base_x = x, base_y = y;
int ret = 0;
if (x == sx || y == sy)
return 0;
max_coin = do_count_coin(a, sx, sy, x + 1, y + 1);
for (; x < sx; x++) {
if (a[base_y * sy + x] == 1) {
ret = do_count_coin(a, sx, sy, x + 1, base_y + 1);
if (max_coin < ret + 1)
max_coin = ret + 1;
}
}
for (; y < sy; y++) {
if (a[y * sy + base_x] == 1) {
ret = do_count_coin(a, sx, sy, base_x + 1, y + 1);
if (max_coin < ret + 1)
max_coin = ret + 1;
}
}
return max_coin;
}
int get_max_coin(int *a, int sx, int sy)
{
int max_coin = do_count_coin(a, sx, sy, 1, 1);
if (a[0] == 1)
return max_coin + 1;
return max_coin;
}
void decode_and_print(const char* code, char *decode, int idx)
{
int len = 0;
int offset = 'a' - 1;
char code_str[3];
len = strlen(code);
if (len == 0) {
decode[idx] = '\0';
printf("%s\n", decode);
return;
}
code_str[2] = '\0';
code_str[1] = '\0';
code_str[0] = code[0];
decode[idx] = (char)(atoi(code_str) + offset);
decode_and_print(&code[1], decode, idx + 1);
if (len > 1) {
code_str[1] = code[1];
decode[idx] = (char)(atoi(code_str) + offset);
decode_and_print(&code[2], decode, idx + 1);
}
}
void decode(const char *code)
{
int len = 0;
char *decoded_string;
decoded_string = (char *)malloc(strlen(code) + 1);
decode_and_print(code, decoded_string, 0);
free(decoded_string);
}
- smartbeast June 23, 2016