#include<stdio.h>
int main(){
int T, N, K;
scanf("%d", &T);
for(int i = 1; i <= T; i++){
scanf("%d %d", &N, &K); getchar();
char hall;
int hold = 0;
for(int j = 0; j < N; j++){
scanf("%c", &hall); getchar();
printf("Case #%d:", i);
if(hall == '0'){
hold++;
} else{
hold = 0;
}
if(hold >= K){
printf("Dead\n");
return 0;
}
}
printf("Alive\n");
return 0;
}
return 0;
}
I got a case where i need to make a program that we must know the outcome of a man who trapped inside a building that caught on fire, we have to make a program where we know he ended up Dead or Alive. This problem includes a testcase (int T), length of a hall (int N), and the duration of the man's capability to hold his breath (int K). In the int N (hall) will contain '0' and '1' where each of it indicates there's stair (1) and there's no stair (0); if there's stair that means the man can take a breath.
Example input:
2 -> this is how many testcase
8 2 -> int N and int K, case 1
01010100 -> int N numbers
10 3 -> case 2
0001001110
The output should be:
Case #1: Dead
Case #2: Alive
Code above already works, but i wonder where should i put the printf("Case #%d:", i); because if i put it there, the if wont run so it wont print either Dead or Alive. Does anyone have an idea?