杭电OJ 5387 Clock

Clock

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 529    Accepted Submission(s): 356


Problem Description
Give a time.(hh:mm:ss),you should answer the angle between any two of the minute.hour.second hand
Notice that the answer must be not more 180 and not less than 0
 

Input
There are  T (1T104)  test cases
for each case,one line include the time

0hh<24 , 0mm<60 , 0ss<60
 

Output
for each case,output there real number like A/B.(A and B are coprime).if it's an integer then just print it.describe the angle between hour and minute,hour and second hand,minute and second hand.
 

Sample Input
  
  
4 00:00:00 06:00:00 12:54:55 04:40:00
 

Sample Output
  
  
0 0 0 180 180 0 1391/24 1379/24 1/2 100 140 120
Hint
每行输出数据末尾均应带有空格
此题首先要弄清分 秒 时三者之间的关系。然后我是计算它们三者到12点钟方向的角度,它们三者角度差的绝对值就是它们之间的角度。当然,由于题目特殊要求,记录数据我是用分子分母两个部分记录。同时求最大公约数的函数用递归貌似会出现“爆栈”的问题,所以没用递归实现。
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #include<algorithm> #include<stack> #include<queue> #include<vector> using namespace std; long long T; long long H,M,S; long long SM,SZ,MM,MZ,HM,HZ; char c,s[10]; long long t,mom,son; long long gcd(long long a,long long b) {            long long tt; if(a<b) swap(a,b); //return b==0?a:gcd(b,a%b); while(b) { tt=a; a=b; b=tt%b; } return a; } int main() {     while(cin>>T)     {         while(T--)         {             cin>>s;             H=(*s-'0')*10 + s[1]-'0';             M=(s[3]-'0')*10 + s[4]-'0';             S=(s[6]-'0')*10 + s[7]-'0';                          if(H>=12) H-=12;   //=12也要减哦                           SZ=S*6;             SM=1;                 //cout<<SM<<" "<<SZ<<endl;///                          //t=gcd(10,S);             //MZ=M*6;             MZ=60*M+S;             MM=10;   //cout<<MM<<" "<<MZ<<endl;///             t=gcd(MZ,MM);             MM/=t;             MZ/=t;                          //HZ=H*30;             HM=120;             HZ=3600*H + 60*M + S;      //cout<<HM<<" "<<HZ<<endl;///             t=gcd(HM,HZ);             HZ/=t;             HM/=t;                                       mom = HM*MM;             son = abs(HZ*MM - MZ*HM);             if(son>180*mom) {son=360*mom - son;}             t=gcd(son,mom);             if(son%mom == 0) cout<<son/mom<<" ";             else cout<<(son)/t<<"/"<<(mom)/t<<" ";                                       mom = HM*SM;             son = abs(HZ*SM - SZ*HM);             if(son>180*mom) {son=360*mom - son;}             t=gcd(son,mom);             if(son%mom == 0) cout<<son/mom<<" ";             else cout<<(son)/t<<"/"<<(mom)/t<<" ";                                       mom = MM*SM;             son = abs(MZ*SM - SZ*MM);             if(son>180*mom) {son=360*mom - son;}             t=gcd(son,mom);             if(son%mom == 0) cout<<son/mom<<" ";             else cout<<(son)/t<<"/"<<(mom)/t<<" ";  //                          cout<<endl;                      }     }     return 0; }
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值