7 条题解

  • 1
    @ 2025-4-18 17:45:30

    #include #include #include<string.h> #include<stdio.h> #include<math.h> #include #include using namespace std; int main(){ int a,b,c,d; cin>>a>>b>>c>>d; cout<<a<<"/"<<b<<"+"<<c<<"/"<<d<<"="; int x,y; x=bd; y=ad+b*c; int r,ax,in; ax=max(x,y); in=min(x,y); r=ax%in; while(r != 0){ ax = in; in=r; r=ax%in; } int aa,bb,zs; aa=y/in; bb=x/in; if(aa>bb){ zs=(aa-aa%bb)/bb; aa%=bb; cout<<zs<<"+"<<aa<<"/"<<bb; }else{ cout<<aa<<"/"<<bb; } return 0; }

    • 1
      @ 2023-3-28 21:05:25
      #include <bits/stdc++.h>//直接使用万能头
      using namespace std;
      int gcd(int a,int b){
      	if(b == 0){
      		return a;
      	}
      	return gcd(b,a % b);
      }
      int main(){
      	int a,b,c,d;
      	cin >> a >> b >> c >> d;
      	int aa = a * d + b * c,bb = b * d,x = gcd(aa,bb);
      	aa /= x;
      	bb /= x;
      	if(aa > bb){
      		cout << a << "/" << b << "+" << c << "/" << d << "=" << aa / bb << "+" << aa % bb << "/" << bb;
      	}
      	else{
      		cout << a << "/" << b << "+" << c << "/" << d << "=" << aa << "/" << bb;
      	}
      	return 0;
      	}
      
      • 1
        @ 2022-12-23 23:45:01
        #include<iomanip>
        #include<stdio.h>
        #include<math.h>
        #include<cstring>
        using namespace std;
        int main(){
        	int a,b,c,d;
        	cin>>a>>b>>c>>d;
        	cout<<a<<"/"<<b<<"+"<<c<<"/"<<d<<"=";
        	int x,y;
        	x=b*d;//分母
        	y=a*d+b*c;//分子
        	int r,ax,in;
        	ax=max(x,y);//大数(用来求最大公倍数)
        	in=min(x,y);//小数
        	r=ax%in;//r为余数
        	while(r!=0){//while求最大公倍数来化简
        		ax=in;
        		in=r;
        		r=ax%in;
        	}
        	int aa,bb,zs;//约分后的分子分母与输出答案的整数部分
        	aa=y/in;
        	bb=x/in;
        	if(aa>bb){//求整数部分
        		zs=(aa-aa%bb)/bb;
        		aa%=bb;
        		cout<<zs<<"+"<<aa<<"/"<<bb;
        	}else{//分情况
        		cout<<aa<<"/"<<bb;
        	}
        	return 0;
        }
        
        • 1
          @ 2022-8-26 18:31:06
          #include <stdio.h>
          #include <iostream>
          using namespace std;
          int main()
          {
          	int a, b, c, d;
          	cin >> a >> b >> c >> d;
          	// printf("%d/%d+%d/%d=",a,b,c,d);
          	cout << a << "/" << b << "+" << c << "/" << d << "=";
          	int y = b*d;
          	int x = a*d + c*b;
          	if(x>y)
          	{
          		cout << x/y;
          		x = x%y;
          		if(x%y !=0)
          		{
          			cout << "+";
          		}
          	}
          	a = x, b = y;
          	while(b)
          	{
          		int t = a%b;
          		a = b;
          		b = t;
          	} 
          	if(a != 0)
          	{
          		x = x/a;
          		y = y/a;
          		cout << x << "/"<<y<<endl;
          
          	}
          }
          
          • 0
            @ 2025-6-15 17:56:28
            
            ```#include <stdio.h>
            #include <iostream>
            #include <math.h>
            using namespace std;
            int main()
            {
            	int a,b,c,d;
            	cin>>a>>b>>c>>d;
            	cout<<a<<"/"<<b<<"+"<<c<<"/"<<d<<"=";
            	int y=b*d;
            	int x=a*d+c*b;
            	if (x>y)
            	{
            		cout<<x/y;
            		x=x%y;
            		if(x%y!=0)
            		{
            			cout<<"+";
            		}
            	}
            	a=x,b=y;
            	while(b)
            	{
            		int t=a%b;
            		a=b;
            		b=t;
            	}
            	if(a!=0)
            	{
            		x=x/a;
            		y=y/a;
            		cout<<x<<"/"<<y<<endl;
            	}
            }
            • 0
              @ 2025-6-5 12:54:57

              #include #include using namespace std; int main() { int a, b, c, d, denominator, numerator, gcd, integerPart, remainder; cin >> a >> b >> c >> d; numerator = a * d + c * b; denominator = b * d; gcd = __gcd(numerator, denominator); numerator /= gcd; denominator /= gcd; integerPart = numerator / denominator; remainder = numerator % denominator; cout << a << "/" << b << "+" << c << "/" << d << "="; if (remainder == 0) { cout << integerPart; } else if (integerPart == 0) { cout << remainder << "/" << denominator; } else { cout << integerPart << "+" << remainder << "/" << denominator; } return 0; }

              • -1
                @ 2024-3-31 18:31:47
                #include <bits/stdc++.h> //使用万能头
                using namespace std;
                int zdgys(int a,int b){ //用辗转相除法求最大公因数(a,b)
                	int t;
                	if(a < b){ //a和b的值交换
                		t = a;
                		a = b;
                		b = t;
                	}
                	while(a % b != 0){ //开始辗转相除法
                		t = b;
                		b = a % b;
                		a = t;
                	}
                	return b;
                }
                int zxgbs(int a,int b,int c){ //求最小公倍数[a,b],c为最大公因数(a,b)
                	return a * (b / c);
                }
                int a,b,c,d,e,f,g,jga,jgb;
                int main(){
                	cin >> a >> b >> c >> d;
                	cout << a << "/" << b << "+" << c << "/" << d << "=";
                	e = zdgys(b,d);      //
                	f = zxgbs(b,d,e);    //
                	a = a * (f / b);     //通
                	b = f;               //分
                	c = c * (f / d);     //
                	d = f;               //
                	jga = a + c;
                	jgb = b;
                	g = jga / jgb;
                	jga %= jgb;
                	e = zdgys(jga,jgb);
                	if(e != 1){          //
                		jga /= e;        //约
                		jgb /= e;        //分
                	}                    //
                	if(g == 0) cout << jga << "/" << jgb << endl;
                	else cout << g << "+" << jga << "/" << jgb << endl;
                	return 0;
                }
                
                • 1

                信息

                ID
                907
                时间
                1000ms
                内存
                128MiB
                难度
                5
                标签
                递交数
                382
                已通过
                147
                上传者