UVA1122-clock

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

#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;
}


posted on 2012-08-21 10:20  Primo...  阅读(135)  评论(0编辑  收藏  举报