+ 1

# Why is the first if ignored?

#include <stdio.h> #include <stdlib.h> int main(void) { int t; int *a; int *b; int diff1=0,diff2=0,diff3=0,diff4=0,diff5=0,diff6=0; int temp1=0,temp2=0; scanf("%d",&t); a=malloc(t*sizeof(int)); b=malloc(t*sizeof(int)); // for t inputs for(int o=0;o<t;o++){ scanf("%d %d",(a+o),(b+o)); //if first element is greater if(a[o]>b[o]){temp1++; diff1=(a[o]-b[o]); if(diff2>=diff1){diff3=diff2; diff2=diff1;} else{diff3=diff1;diff2=diff1;} } // if second element is greater else{temp2++; diff4=(b[o]-a[o]); if(diff5<=diff4){diff6=diff4; diff5=diff4;} else{diff6=diff5;diff5=diff4;} } } if(temp1>temp2){printf("1 ");printf("%d",diff3);} else{printf("2 ");printf("%d",diff6);} return 0; } /*input:7 1 4 1 5 3 7 3 8 3 7 5 2 4 7*/

30th Dec 2021, 7:33 AM
Ishaan Oberoi
0
sorry, question should be where is the error? https://code.sololearn.com/cz0dkqpa69U4/#c code
30th Dec 2021, 7:36 AM
Ishaan Oberoi
0
There is no error. What are you trying by this code? Your input has only one a[o]>b[o] is true so temp1>temp2 is 1>6 is false so first if ingored by that specific input..
30th Dec 2021, 9:34 AM
Jayakrishna đźđł
0
@Jayakrishna https://www.codechef.com/problems/TLG this is the problem. i should get 2 5 if i enter 3 1 6 15 1 4 but i gt 2 4
30th Dec 2021, 10:23 AM
Ishaan Oberoi
0
What is essential there of temp++ ? You have to find difference between prayer1 and player2, and bigger difference is winner decider so from that, output bigger scorer and big difference.. edit:Ishaan Oberoi you may counting, how many times winner but it's asking with big difference winner only..
30th Dec 2021, 11:52 AM
Jayakrishna đźđł
0
It's an Error Code In My Head
30th Dec 2021, 11:52 PM
Jevon Harry