5 条题解
-
1齐硕 LV 10 @ 2022-08-08 15:32:10
#include<iostream>
using namespace std;struct Node
{
int fen_zi;
int fen_mu;
Node *next;
};class LinkList
{
private:
int n;
Node *head;
Node *tail;
public:
LinkList(int set_n)
{
n=set_n;
head=NULL;
tail=NULL;
}void set_list(LinkList &L)
{
int x,y;
for(int i=0;i<L.n;i++)
{
cin>>x>>y;
L.insert(x,y);
}
}void insert(int x,int y)
{
Node *newp=new Node;
newp->fen_zi=x;
newp->fen_mu=y;
if(head==NULL)
{
head=newp;
tail=newp;
}
else
{
tail->next=newp;
tail=newp;
}
if(tail!=NULL)
tail->next=NULL;
}int get_fen_mu()//得到不化简的分子
{
Node *p=head;
int sum=1;
while(p!=NULL)
{
sum=sum*p->fen_mu;
p=p->next;
}
return sum;
}int get_fen_zi(LinkList &L)//得到不化简的分母
{
Node *p=L.head;
int sum=0;
while(p!=NULL)
{
sum=sum+p->fen_zi*L.get_fen_mu()/p->fen_mu;
p=p->next;
}
return sum;
}int yue_shu(int x,int y)//求最大公约数
{
int tmp;
if(x<y)
{
tmp=x;
x=y;
y=tmp;
}
return y==0?x:yue_shu(y,x%y);
}};
int main()
{
int n=2;
//cin>>n;
LinkList start(0);
LinkList List(n);
start.set_list(List);
int x,y;
x=start.get_fen_zi(List)/List.yue_shu(start.get_fen_zi(List),List.get_fen_mu());
y=List.get_fen_mu()/List.yue_shu(start.get_fen_zi(List),List.get_fen_mu());
cout<<x<<" "<<y<<endl;return 0;
} -
-12021-01-27 11:26:45@
#include<bits/stdc++.h>
using namespace std;int main()
{
int b1, a1, a2, b2, a3, b3, aa3,bb3;
cin>>b1;
cin>>a1;
cin>>b2;
cin>>a2;
int aa1=a1, aa2=a2;
while( 1 ) //两分母最大公因数
{
a3=aa1%aa2;
if(a3==0)
break;
aa1=aa2; aa2=a3;
}
b3=a1/aa2*a2;//最小公倍数
b1=b3/a1*b1;//b1分子扩大
b2=b3/a2*b2;//b2分子扩大
bb3=b1+b2;//b1+b2
int bb1=b3, bb2=bb3;//化简
while( 1 ) //分子、分母最大公因数
{
aa3=bb1%bb2;
if(aa3==0)
break;
bb1=bb2; bb2=aa3;
}
b1=bb3/bb2;//分子化简
b2=b3/bb2;//分母化简
cout<<b1<<" "<<b2<<endl;
return 0;
} -
-12021-01-25 17:30:55@
#include<iostream> using namespace std; int GYS(int a,int b)//求最大公因数的函数 { int c=a%b; while(c) { a=b; b=c; c=a%b; } return b; } int GBS(int a,int b)//求最小公倍数的函数 { int d=GYS(a,b); return a/d*b; } int main() { int b1,b2; int a1,a2; cin>>b1>>a1>>b2>>a2; int FM,FZ;//分母和分子 FM=GBS(a1,a2); FZ=FM/a1*b1+FM/a2*b2; //约分结果 int c=GYS(FM,FZ); FM/=c; FZ/=c; cout<<FZ<<" "<<FM; return 0; }
-
-12019-11-19 14:23:15@
#include<stdio.h>
int simplify(int n,int m);
int main()
{
int a1,a2,b1,b2,n,m;
scanf("%d%d",&a1,&b1);
scanf("%d%d",&a2,&b2);
n=a1*b2+a2*b1;
m=b1*b2;
simplify(n,m);return 0;
}
int simplify(int m,int n)
{
int i,j;
for(i=1;i<=m&&i<=n;i++)
if(m%i==0&&n%i==0)
j=i;
printf("%d %d",m/j,n/j);//分数约分}
-
-12019-10-20 15:53:29@
#include<iostream> using namespace std; struct Node { int fen_zi; int fen_mu; Node *next; }; class LinkList { private: int n; Node *head; Node *tail; public: LinkList(int set_n) { n=set_n; head=NULL; tail=NULL; } void set_list(LinkList &L) { int x,y; for(int i=0;i<L.n;i++) { cin>>x>>y; L.insert(x,y); } } void insert(int x,int y) { Node *newp=new Node; newp->fen_zi=x; newp->fen_mu=y; if(head==NULL) { head=newp; tail=newp; } else { tail->next=newp; tail=newp; } if(tail!=NULL) tail->next=NULL; } int get_fen_mu()//得到不化简的分子 { Node *p=head; int sum=1; while(p!=NULL) { sum=sum*p->fen_mu; p=p->next; } return sum; } int get_fen_zi(LinkList &L)//得到不化简的分母 { Node *p=L.head; int sum=0; while(p!=NULL) { sum=sum+p->fen_zi*L.get_fen_mu()/p->fen_mu; p=p->next; } return sum; } int yue_shu(int x,int y)//求最大公约数 { int tmp; if(x<y) { tmp=x; x=y; y=tmp; } return y==0?x:yue_shu(y,x%y); } }; int main() { int n=2; //cin>>n; LinkList start(0); LinkList List(n); start.set_list(List); int x,y; x=start.get_fen_zi(List)/List.yue_shu(start.get_fen_zi(List),List.get_fen_mu()); y=List.get_fen_mu()/List.yue_shu(start.get_fen_zi(List),List.get_fen_mu()); cout<<x<<" "<<y<<endl; system("pause"); return 0; }
- 1
信息
- 难度
- 5
- 分类
- (无)
- 标签
- 递交数
- 883
- 已通过
- 324
- 通过率
- 37%
- 被复制
- 10
- 上传者