{
char input[(1<<10) + 1];
fgets(input, 1<<10, stdin);
unpaired_parenthesis(input);
return 0;
}
void unpaired_parenthesis(const char* str) {
static int left = 0, right = 0;
if ('\n' == *str || 0 == strlen(str)) {
printf("%d\n", left + right);
return;
}
if ('(' == *str) {
++left;
} else if (0 != left && ')' == *str) {
--left;
} else {
++right;
}
unpaired_parenthesis(str + 1);
}
Like this?
It looks like you posted long piece of code, consider editing it out and putting it on hastebin.com and pasting link to it instead. Alternatively, send your code in a file.
Awesome man! I was trying this hard 😀
My Unix dev instincts tell me: "O noes, why thou uses fget for the stdin when thou have read"
Обсуждают сегодня