```c
#include
#include
int main()
{
int h=0,m=0,s=0;
double d,v1,v2,x1,x2,t,r,o,p,q;
scanf("%lf%lf%lf",&d,&v1,&v2);
scanf("%lf%lf%lf",&o,&p,&q);
x1=v15/18,x2=v15/18;r=1000d;
if(v1>=v2)
printf("None\n");
else
{
double i=3600;
t=r/(x2/x1);
while(t/i!=0)
{
h++;
i=(h+1);
}
t=fmod(t,3600);double j=60;
while(t/j!=0)
{
m++;
j*=(m+1);
}
s=fmod(t,60);
s=s+q;
if(s>=60)
{
s++;
s=fmod(s,60);
}
if(m>=60)
{
h++;
m=m%60;
}
while(h>24)
{
h=h-24;
}
printf("%d:%d:%d\n",h,m,s);
}
return 0;
}
输入样例2
16.56
1.05 2.67
12:36:4.5
输出样例2
22:49:24.50
```a.c: In function ‘main’:
a.c:7:5: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%lf%lf%lf",&d,&v1,&v2);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.c:8:5: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%lf%lf%lf",&o,&p,&q);
^~~~~~~~~~~~~~~~~~~~~~~~~~~
#include<stdio.h>
#include<math.h>
int main()
{
int h=0,m=0,s=0;
double d,v1,v2,x1,x2,t,r,o,p,q;
scanf("%lf%lf%lf",&d,&v1,&v2);
scanf("%lf%lf%lf",&o,&p,&q);
x1=v1*5/18,x2=v1*5/18;r=1000*d;
if(v1>=v2)
printf("None\n");
else
{
t=r/(x2/x1);
while(t >= 3600)
{
h++;
t -= 3600;
}
while(t >= 60)
{
m++;
t -= 60;
}
s = t;
s += q;
if(s >= 60)
{
m++;
s -= 60;
}
if(m >= 60)
{
h++;
m -= 60;
}
while(h > 24)
{
h -= 24;
}
printf("%d:%d:%d\n", h, m, s);
}
return 0;
}
你的代码有几个问题:
#include<stdio.h>
#include<math.h>
int main()
{
int h=0,m=0,s=0;
double d, v1, v2, x1, x2, t, r, o, p, q;
// Read input and check return value of scanf
if (scanf("%lf%lf%lf",&d,&v1,&v2) != 3) {
printf("Error reading input\n");
return 1;
}
if (scanf("%lf%lf%lf",&o,&p,&q) != 3) {
printf("Error reading input\n");
return 1;
}
x1 = v1 * (d / v1 - d / v2); // Calculate x1
x2 = v2 * (d / v1 - d / v2); // Calculate x2
r = 1000;
t = r / (x2 / x1); // Calculate time
// Convert time to hours, minutes, and seconds
while(t >= 3600) {
h++;
t -= 3600;
}
while(t >= 60) {
m++;
t -= 60;
}
s = t;
// Add time passed since last hour
s += q;
if (s >= 60) {
s -= 60;
m++;
}
if (m >= 60) {
m -= 60;
h++;
}
while(h > 24) {
h -= 24;
}
printf("%d:%d:%d\n",h,m,s);
return 0;
}