AcWing 668. 游戏时间2
原题链接
中等
作者:
小赵想滑板
,
2024-01-28 14:07:42
,
所有人可见
,
阅读 42
C++ 代码
#include <iostream>
using namespace std;
int main(){
int a,b,c,d;
cin>>a>>b>>c>>d;
if(a<c){
if(b>d)
cout<<"O JOGO DUROU "<<c-a-1<<" HORA(S) E "<<d+60-b<<" MINUTO(S)";
else cout<<"O JOGO DUROU "<<c-a<<" HORA(S) E "<<d-b<<" MINUTO(S)";
}else if(a>c){
if(b<d)
cout<<"O JOGO DUROU "<<c-a+24<<" HORA(S) E "<<d-b<<" MINUTO(S)";
else cout<<"O JOGO DUROU "<<c-a+23<<" HORA(S) E "<<d-b+60<<" MINUTO(S)";
}else{
if(b<d)
cout<<"O JOGO DUROU "<<0<<" HORA(S) E "<<d-b<<" MINUTO(S)";
else if(b>d)
cout<<"O JOGO DUROU "<<23<<" HORA(S) E "<<d-b+60<<" MINUTO(S)";
else
cout<<"O JOGO DUROU "<<24<<" HORA(S) E "<<0<<" MINUTO(S)";
}
}
取余思路版
#include<iostream>
using namespace std;
int main()
{
int a,b,c,d;
cin>>a>>b>>c>>d;
b+=a*60,d+=c*60;
a=(d-b+24*60)%(24*60);
a=(a)?(a):(24*60);
printf("O JOGO DUROU %d HORA(S) E %d MINUTO(S)\n",a/60,a%60);
return 0;
}