img

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int gcd(int a, int b)
{
    if (a % b==0) return b;
    else return gcd(b, a % b);
}//շת���������
class FS
{
	private:
		int fz,fm;
	public:
		friend int gcd(int a,int b);
		void set(int newfz,int newfm)
		{
			fz=newfz;fm=newfm;
		}
		
		FS operator + (const FS &f)
		{
			fz=fz*f.fm+f.fz*fm;
			fm=f.fm*fm;
			
			int t=gcd(fz,fm);
			fz=fz/t;fm=fm/t;
			
			if(fm<0){fm=-fm;fz=-fz;}
			
			FS f_new;
			f_new.set(fz,fm);
			return f_new;
		}
		
		void display()
		{
			cout<<fz<<"z"<<fm<<"m"<<endl;
		}
	
			
}; 
int main()
{
	int n;
	cin>>n;
	int i;
	for(i=1;i<=n;i++)
	{
		FS fs1,fs2,fs3;
		int z,m;
		char z1,m1;
		cin>>z>>z1>>m>>m1;
		fs1.set(z,m);
		cin>>z>>z1>>m>>m1;
		fs2.set(z,m);
		
		fs3=fs1+fs2;
		fs3.display();
	}
    return 0;
}

img

#include<iostream>
using namespace std;
class Time
{
private:
	int hour;
	int minute;
public:
	Time(){}
	Time(int h,int m):hour(h),minute(m){}
	void set(int h, int m)
	{
		hour = h;
		minute = m;
	}
	int operator-(const Time& t)
	{
		return hour * 60 + minute - t.hour * 60 - t.minute;
	}
};
int main()
{
	int a, b, c, d;
	while (1)
	{
		Time t1, t2;
		cin >> a >> b >> c >> d;
		if (a == 00 && b == 00 && c == 00 && d == 00) break;
		t1.set(a, b);
		t2.set(c, d);
		int res = t2 - t1;
		cout << res << endl;
	}
}
posted on 2023-05-19 19:57  许七安gyg  阅读(1)  评论(0编辑  收藏  举报
$(document).ready(function() { // 禁止右键 $(document).bind("contextmenu", function(){return false;}); // 禁止选择 $(document).bind("selectstart", function(){return false;}); // 禁止Ctrl+C 和Ctrl+A $(document).keydown(function(event) { if ((event.ctrlKey&&event.which==67) || (event.ctrlKey&&event.which==86)) { //alert("对不起,版权所有,禁止复制"); return false; } }); });