#include <bits/stdc++.h>
using namespace std ;
int main() {
int h1,m1,h2,m2,ans1,ans2,ans3,ans4;
while(cin>>h1>>m1>>h2>>m2){
if(h1==0 && m1==0 && h2==0 && m2==0) break;
if(h1<h2){
ans1=(h2*60+m2)-(h1*60+m1);
cout<<ans1<<endl;
}
if(h1==h2&&m1<m2){
ans2=m2-m1;
cout<<ans2<<endl;
}
if(h1==h2&&m1>m2){
ans3=1440+(m2-m1);
cout<<ans3<<endl;
}
if(h1>h2){
ans4=(h2+24-h1)*60+(m2-m1);
cout<<ans4<<endl;
}
ans1==0; ans2==0; ans3==0; ans4==0;
}
}
#include <bits/stdc++.h>
using namespace std ;
int main() {
int h1,m1,h2,m2,ans1,ans2,ans3,ans4;
while(cin>>h1>>m1>>h2>>m2){
if(h1==0 && m1==0 && h2==0 && m2==0) break;
if(h1<h2){
ans1=(h2*60+m2)-(h1*60+m1);
cout<<ans1<<endl;
}
if(h1==h2&&m1<m2){
ans2=m2-m1;
cout<<ans2<<endl;
}
if(h1==h2&&m1>m2){
ans3=1440+(m2-m1);
cout<<ans3<<endl;
}
if(h1>h2){
ans4=(h2+24-h1)*60+(m2-m1);
cout<<ans4<<endl;
}
ans1==0; ans2==0; ans3==0; ans4==0;
}
}
最後一行把==換成=
我的AC程式碼:
#include <iostream> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv) { int a,b,c,d; while(cin>>a>>b>>c>>d){ if(a==0&&b==0&&c==0&&d==0)break; if(c>a||c==a&&b<=d){ cout<<(c-a)*60+d-b<<endl; }else if(a>=c&&d>=b){ cout<<(c-a+24)*60+b-d<<endl; }else if(a>=c&&d<b){ cout<<(c-a+24)*60+d-b<<endl; } } return 0; }
更精簡的做法:
#include <iostream> using namespace std; int main() { int a, b, c, d; while (cin >> a >> b >> c >> d && a + b + c + d != 0) cout << ((c * 60 + d) - (a * 60 + b) + 1440) % 1440 << endl; }
更精簡的做法:
#include using namespace std; int main() { int a, b, c, d; while (cin >> a >> b >> c >> d && a + b + c + d != 0) cout << ((c * 60 + d) - (a * 60 + b) + 1440) % 1440 << endl; }
我的是:
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv){
int a,b,c,d;
while(cin>>a>>b>>c>>d&&a+b+c+d!=0)
cout<<((c+24-a)%24*60+d-b+1440)%1440<<endl;
}