Miles_Morales @ 2024-09-25 10:51:52
同样是if反复判定 为什么两个思路一个倒着减回去只有60分 正着加上去的就满分了
60分版本如下
#include<bits/stdc++.h>
using namespace std;
int main()
{
double s, v;
cin >> s >> v;
double t1 = s / v;
int t = ceil(t1);
int h = t / 60;
int m = t % 60;
int H,M;
if(h<=7)
{
H=7-h;
if (m >= 50 && m<=59)
{
h = h + 1;
m = m - 50;
M = 60 - m;
printf("0%d:0%d", H, M);
}
else if(m>=60)
{
h = h + 1;
m = m - 50;
M = 60 - m;
printf("0%d:%d", H, M);
}
else
{
M = 50 - m;
printf("0%d:%d", H, M);
}
}
else
{
H=24-(h-7);
if (m >= 50 && m<=59)
{
h = h + 1;
m = m - 50;
M = 60 - m;
printf("%d:0%d", H, M);
}
else if(m>=60)
{
h = h + 1;
m = m - 50;
M = 60 - m;
printf("%d:%d", H, M);
}
else
{
M = 50 - m;
printf("%d:%d", H, M);
}
}
return 0;
}
100分版本如下
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
double s, v;
cin >> s >> v;
int T, t1,t2;
T = 24 * 60 + 8 * 60;
t1 = ceil(s / v) + 10;
t2 = T - t1;
int h, m;
h = t2 / 60;
m = t2 % 60;
if (h >= 24)
{
h = h - 24;
if (m >= 10)
{
printf("0%d:%d", h, m);
}
else
{
printf("0%d:0%d", h, m);
}
}
else if (h < 10)
{
if (m >= 10)
{
printf("0%d:%d", h, m);
}
else
{
printf("0%d:0%d", h, m);
}
}
else
{
if (m >= 10)
{
printf("%d:%d", h, m);
}
else
{
printf("%d:0%d", h, m);
}
}
return 0;
}
感谢帮助!!!