Problem Link: MAGICHF Problem - CodeChef
Feedback
I cannot understand, why code
include <stdio.h>
void result(){
}
void task(int N){
int total_swaps,
total_boxes,
current_box_with_coin,
swap_box_A,swap_box_B;
for(int i = 0;i < N;i++){
scanf(“%d%d%d”,&total_boxes,¤t_box_with_coin,&total_swaps);
for(int j = 0;j < total_swaps;j++){
scanf(“%d%d”,&swap_box_A,&swap_box_B);
current_box_with_coin = (current_box_with_coin == swap_box_A)?swap_box_B:swap_box_A;
}
printf(“%d\n”,current_box_with_coin);
}
}
int main(void) {
int N;
scanf(“%d”,&N);
task(N);
return 0;
}
crash on tests, but code
include <stdio.h>
void result(){
}
void task(int N){
int total_swaps,
total_boxes,
current_box_with_coin,
swap_box_A,swap_box_B;
for(int i = 0;i < N;i++){
scanf(“%d%d%d”,&total_boxes,¤t_box_with_coin,&total_swaps);
for(int j = 0;j < total_swaps;j++){
scanf(“%d%d”,&swap_box_A,&swap_box_B);
if(current_box_with_coin == swap_box_A) current_box_with_coin = swap_box_B;
else if(current_box_with_coin == swap_box_B) current_box_with_coin = swap_box_A;
}
printf(“%d\n”,current_box_with_coin);
}
}
int main(void) {
int N;
scanf(“%d”,&N);
task(N);
return 0;
}
doing well, because both of them do same logic.