您的位置:首页 > 其它

厦大oj1438简单题、数学题(积分、几何概率、求最大公约数)

2013-04-20 18:20 357 查看
#include<iostream>
#include<string>
#include<fstream>
using namespace std;

int time_to_int(string time){
int time_int = 0;
int hour = 0;
int minute = 0;
if(time[0] != '0'){
hour = (int)(time[0] - 48);
time_int += hour * 60 * 10;
}
if(time[1] != '0'){
hour = (int)(time[1] - 48);
time_int += hour * 60;
}
if(time[3] != '0'){
minute = (int)(time[3] - 48);
time_int += minute * 10;
}
if(time[4] != '0'){
minute = (int)(time[4] - 48);
time_int += minute;
}
return time_int;
}

int gcd(int a, int b){
if(a<0)
return gcd(-a, b);
if(b<0)
return gcd(a, -b);
return (b == 0)? a : gcd(b, a % b);
}

int main(){
string s1, s2;
int fenzi;
int fenmu;
int m, time1, time2, time_dis;
//ifstream ifs("shuju.txt");
//ifs>>s1>>s2>>m;//
cin>>s1>>s2>>m;
time1 = time_to_int(s1);
time2 = time_to_int(s2);
time_dis = time2 - time1;
if(time_dis < m){
cout<<1<<"/"<<2;
//system("pause");
return 0;
}
//cout<<time_dis<<endl;//
fenzi = 2 * (time_dis - m) * m + m * m;
fenmu = 2 * time_dis * time_dis;
//cout<<fenzi<<fenmu<<endl;
int zuidagongyueshu = gcd(fenzi, fenmu);
//cout<<zuidagongyueshu<<endl;
fenzi /= zuidagongyueshu;
fenmu /= zuidagongyueshu;
cout<<fenzi<<"/"<<fenmu;
//system("pause");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: