ProgrammingVery hardCompetitive coding (CP)
What is printed?
What is printed?
#include <stdio.h>
char g[3][4] = {"110", "010", "011"};
int fill(int r, int c) {
if (r < 0 || c < 0 || r >= 3 || c >= 3 || g[r][c] != '1') return 0;
g[r][c] = '0';
return 1 + fill(r + 1, c) + fill(r - 1, c) + fill(r, c + 1) + fill(r, c - 1);
}
int main(void) {
printf("%d", fill(0, 0));
}- A. 4
- B. 3
- C. 6
- D. 5
Correct answer: D. 5
The flood fill from (0,0) reaches (0,1), (1,1), (2,1) and (2,2), so the component has five cells. The cell (1,0) is 0 and blocks nothing else.
More C Programming questions
- What is printed? c #include <stdio.h> #include <stdlib.h> int cmp(const void a, const void b) { const int x = a, y = b; int sx = x[0] +…
- What is printed? c #include <stdio.h> #include <stdlib.h> struct Item { int id; char tag; }; int cmp(const void k, const void e) { const…
- What is printed? c #include <stdio.h> int digitsum(unsigned long long n) { return n == 0 ? 0 : (int)(n % 10) + digitsum(n / 10); } int…
- What is printed? Assume uint8t is 8 bits. c #include <stdint.h> #include <stdio.h> int main(void) { uint8t x = 3; for (int i = 0; i < 5…
- What is printed? c #include <stdio.h> int main(void) { printf("%d", 07 + 0x10); }
- What is printed? c #include <stdio.h> int main(void) { unsigned mask = ~0u << 4; printf("%X", mask >> 28); }