廈大oj1438簡單題、數學題(積分、幾何機率、求最大公約數)

來源:互聯網
上載者:User
#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;  }  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.