算是最好写的一道题了吧,最近模拟没手感,一次过也是很鸡冻o(* ̄▽ ̄*)o

注意事项都在代码里,没有跳坑也不清楚坑点在哪~

 #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<cmath>
#include<sstream>
#include<iostream>
using namespace std;
const double eps = 1e-;
int hh, mm, ss;
int gcd(int a, int b)
{
return b == ? a : gcd(b, a%b);
}
void sub(int a, int b, int c, int d)
{ //分数相减(a/b - c/d = (ad-bc)/bd),各种凌乱的特判,注意取绝对值输出
if(c == ) //c/d = 0,直接输出a/b
{
if(b == ) printf("%d", abs(a));
else printf("%d/%d", abs(a), abs(b));
return;
}
int t1 = b*d, t2 = a*d - b*c;
if(t1 == || t2 == ) //分子或分子为0,直接输出0
{
printf("");
return;
}
int t12 = gcd(t1, t2); //化简
int tt1 = t1/t12;
int tt2 = t2/t12;
if(tt1 == ) printf("%d", abs(tt2));
else printf("%d/%d", abs(tt2), abs(tt1));
} void get_ang(double a1, double a2, int t11, int t12, int t21, int t22)
{
if(fabs(a1 - a2) < eps) //两角相等
{
printf("");
return ;
}
if(fabs(a1 - a2) > ) //注意两角相差大于180度
{
if(a1 > a2)
{
t11 = t11 - *t12; //大角减360度,然后二者相减去绝对值,这里动手画一下就清楚了
sub(t11, t12, t21, t22);
}
else
{
t21 = t21 - *t22;
sub(t21, t22, t11, t12);
}
}
else if(fabs(a1 - a2) <= )
{
if(a1 > a2)
sub(t11, t12, t21, t22);
else
sub(t21, t22, t11, t12);
}
}
void solve()
{
int h = hh* + mm* + ss; //化成秒为单位
int m = mm* + ss;
int s = ss;
int ansh1, ansh2, ansm1, ansm2, anss1, anss2; //主要化简成分数计算
int gh, gm; //时针化为秒数与120的最大公约数,分针化为秒数与10的最大公约数
double ah, am, as; //用double比较三针走过的度数大小
if(h)
{
gh = gcd(h, );
ansh1 = h/gh, ansh2 = /gh;
ah = (double)ansh1/ansh2;
}
else
{
ansh1 = , ansh2 = ;
ah = 0.0;
}
if(m)
{
gm = gcd(m, );
ansm1 = m/gm, ansm2 = /gm;
am = (double)ansm1/ansm2;
}
else
{
ansm1 = , ansm2 = ;
am = 0.0;
}
if(s)
{
anss1 = s*, anss2 = ;
as = (double)anss1/anss2;
}
else
{
anss1 = , anss2 = ;
as = 0.0;
}
get_ang(ah, am, ansh1, ansh2, ansm1, ansm2); printf(" ");
get_ang(ah, as, ansh1, ansh2, anss1, anss2); printf(" ");
get_ang(am, as, ansm1, ansm2, anss1, anss2); printf(" ");
}
int main()
{
int T;
scanf("%d", &T);
getchar();
while(T--)
{
string str;
cin >> str;
for(int i = ; i < str.length(); i++)
if(str[i] == ':')
str[i] = ' '; //方便用stringstream,用这个耗时会比较大,处理方法随意~ stringstream SS(str);
SS >> hh;
SS >> mm;
SS >> ss;
if(hh == && (mm || ss)) hh -= ;
else if(hh > ) hh -= ; //24小时制转为12小时
solve();
printf("\n");
}
return ;
}

hdu-5387

最新文章

  1. eclipse部署上Tomcat后的clean和publish功能
  2. 迁移SQL SERVER 数据库实例
  3. linux su和sudo命令的区别(转)
  4. :“boost/serialization/string.hpp”: No such file or directory 错误
  5. java.lang.IllegalArgumentException: addChild: Child name &#39;/SSHE&#39; is not unique
  6. bistu新生-1005
  7. shell中trap捕获信号
  8. shell 脚本中for循环
  9. SQL练习题完整(做完你就是高手)
  10. win10 uwp 切换主题
  11. J2EE--常见面试题总结 -- (二)
  12. 第十四章——循环神经网络(Recurrent Neural Networks)(第二部分)
  13. 前端——BOM和DOM
  14. Django 日志输出及打印--logging
  15. SpringSecurityOAuth认证配置及Token的存储
  16. js selection对象使用方法
  17. AngularJS使用OData请求ASP.NET Web API资源的思路
  18. [转]mysql delete 使用别名 语法
  19. 17,UC(06)
  20. 如何搭建本地WordPress

热门文章

  1. Android实例-获取程序版本号(XE10+小米2)
  2. Android实例-读取设备联系人(XE8+小米2)
  3. ASP.NET面试题总结
  4. 语义Web和本体开发相关技术
  5. 部署 instance 到 OVS flat network - 每天5分钟玩转 OpenStack(135)
  6. MsSQL的游标的综合运用
  7. Educational Codeforces Round 1 C. Nearest vectors 极角排序
  8. 怎样在osg中动态的设置drawable的最近最远裁剪面
  9. [置顶] ASP.NET MVC - Model Binding
  10. WebFormJS注册位置