欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

UVA1122-clock

程序员文章站 2022-07-04 11:01:43
此题的难点是表盘的规律,时针和分针相遇的时刻是60*hour/11,还有,常疏忽的地方是第一行和最后一行的两句话、 [html]  #include &nb...

此题的难点是表盘的规律,时针和分针相遇的时刻是60*hour/11,还有,常疏忽的地方是第一行和最后一行的两句话、

[html] 
#include <iostream> 
#include <iomanip> 
using namespace std; 
int main () 

    cout<<"program 3 by team x"<<endl; 
    int  a, b, c, d; 
    cout<<"initial time  final time  passes"<<endl; 
    while(cin>>a>>b>>c>>d) 
    { 
        int n = c - a; 
        if(n==0&&d<b) n+=11; 
        if(n<0)n += 11; 
        n += 13; 
        if(((60*(a)/11))<b)n -= 1; 
        if(c==12)n-=1; 
        else if(d<((60*(c%12)/11)))n -= 1; 
        n %= 12; 
        cout<<"       "; 
        if(a/10==0)cout<<0; 
        cout<<a<<":"; 
        if(b/10==0)cout<<0; 
        cout<<b; 
        cout<<"       "; 
        if(c/10==0)cout<<0; 
        cout<<c<<":"; 
        if(d/10==0)cout<<0; 
        cout<<d; 
        cout<<"      "; 
        if(a==c&&d==b)n=11; 
        if(n/10==0)cout<<' '; 
        cout<<n; 
        cout<<endl; 
 
    }cout<<"end of program 3 by team x"<<endl; 
    return 0;