Chef and Girlfriend is giving wrong answer

Below code is giving wrong answer ,i want to know in which case its failing
Below is the link to question:

my solution:

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);


using namespace std;

int main()
{
	FAST_IO

int T,dist;
cin>>T;
char time1[6],time2[6];
while(T--)
{
float t1_hr,t2_hr,t1_min,t2_min;

scanf("%02f:%02f",&t1_hr,&t1_min);	
scanf("%02f:%02f",&t2_hr,&t2_min);
scanf("%d",&dist);	

	cout<<fixed<<setprecision(1)<<(t1_hr-t2_hr)*60+(t1_min-t2_min)+dist;
float temp_hr=t2_hr,temp_min=(2*dist)+t2_min;

while(temp_min>=60)
{
	temp_hr++;
	temp_min=temp_min-60;
}

if(temp_hr>t1_hr)
{
temp_hr=t2_hr;
temp_min=dist+t2_min;
while(temp_min>=60)
{
	temp_hr++;
	temp_min=temp_min-60;
}
	
cout<<" "<<fixed<<setprecision(1)<<dist+((temp_hr-t1_hr)*60+(t1_min-temp_min))+(dist-(t1_min-temp_min))/2<<"\n";
}
else
{
	
cout<<" "<<fixed<<setprecision(1)<<((t1_hr-t2_hr)*60+(t1_min-(t2_min+2*dist)))+(2*dist)<<"\n";

}



}




    return 0;
}

On my machine, the sample testcase gave wildly wrong answers, probably because you are making the same mistake as this guy :slight_smile:

Edit:

Or this guy, lol XD

2 Likes

I have cahnged it but still giving wrong answer:

#include<stdio.h>

int main()
{
int T,dist;
scanf("%d",&T);
while(T--)
{
//	cin>>time1>>time2>>dist;
	
//	int t1_hour_value=(time1[0]-'0')*10+(time1[1]-'0'), t1_min_value=(time1[3]%48)*10+(time1[4]%48);
//	int t2_hour_value=(time2[0]%48)*10+(time2[1]%48), t2_min_value=(time2[3]%48)*10+(time2[4]%48);
//	int  t2_hour_value_temp=t2_hour_value,t2_min_value_temp=t2_min_value;
float t1_hr,t2_hr,t1_min,t2_min;

scanf("%02f:%02f",&t1_hr,&t1_min);	
scanf("%02f:%02f",&t2_hr,&t2_min);
scanf("%d",&dist);	

	printf("%0.1f",(t1_hr-t2_hr)*60+(t1_min-t2_min)+dist);
float temp_hr=t2_hr,temp_min=(2*dist)+t2_min;

while(temp_min>=60)
{
	temp_hr++;
	temp_min=temp_min-60;
}

if(temp_hr>t1_hr)
{
temp_hr=t2_hr;
temp_min=dist+t2_min;
while(temp_min>=60)
{
	temp_hr++;
	temp_min=temp_min-60;
}
	
printf(" %0.1f\n",dist+((temp_hr-t1_hr)*60+(t1_min-temp_min))+(dist-(t1_min-temp_min))/2);
}
else
{
printf(" %0.1f\n",((t1_hr-t2_hr)*60+(t1_min-(t2_min+2*dist)))+(2*dist));
}


}


    return 0;
}

1 Like

He solved it.

1 Like