不是吧!!!

null him 2021-01-26 10:52:06 8
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int gcd(int n,int c){
	if(n%c==0){
		return c;
	}
	else{
		return gcd(c,n%c);
	}
}
int gbs(int x,int y){
	if(x>=y){
		for(int i=1;;i++){
			if(x*i%y==0){
				return x*i;
			}
		}
	}
	for(int i=1;;i++){
		if(y*i%x==0){
			return i*y;
		}
	}
}
struct fs{
	int fm,fz;
}a[100010];
bool cmp(fs a,fs b){
	return a.fz<b.fz;
}
int main(){
	freopen("C.in","r",stdin);
	freopen("C.out","w",stdout);
	int n,ans=1;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d/%d",&a[i].fz,&a[i].fm);
		ans=gbs(a[i].fm,ans);
	}
	for(int i=1;i<=n;i++){	
		a[i].fz=(ans/a[i].fm)*a[i].fz;
		a[i].fm=ans;
	}
	sort(a+1,a+1+n,cmp);
	for(int i=1;i<=n;i++){
		printf("%d/%d\n",a[i].fz/gcd(a[i].fz,a[i].fm),a[i].fm/gcd(a[i].fz,a[i].fm));
	}
	return 0;
}
{{ vote && vote.total.up }}

共 6 条回复

zhangyihao

#include #include #include using namespace std; struct fs { long long int fm, fz; char fh; double c;

} a[100005]; bool cmp(fs a, fs b) { return a.fz * b.fm < a.fm * b.fz; } int w(int a, int b) { if (a % b == 0) { return b; } else { return w(b, a % b); } } int main() { freopen("C.in", "r", stdin); freopen("C.out", "w", stdout); int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i].fz >> a[i].fh >> a[i].fm; } sort(a + 1, a + 1 + n, cmp); for (int j = 1; j <= n; j++) { cout << a[j].fz / w(a[j].fm, a[j].fz) << "/" << a[j].fm / w(a[j].fm, a[j].fz) << endl; } return 0; }

null him

万分感谢

pikahuan 逗比

我是这么做的

pikahuan 逗比
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
struct stu{
    ll a,b;
}a[100010];
bool cmp(stu x,stu y)
{
    return x.a*y.b<y.a*x.b;
}
ll f(ll a,ll b)
{
    if(b==0)return a;
    return f(b,a%b);
}
ll n,w;
int main()
{
    freopen("C.in","r",stdin);
    freopen("C.out","w",stdout);	
    scanf("%lld",&n);
    for(ll i=1;i<=n;i++)
    {
        scanf("%lld/%lld",&a[i].a,&a[i].b);
        w=f(a[i].a,a[i].b);
        a[i].a/=w,a[i].b/=w;
    }
    sort(a+1,a+1+n,cmp);
    for(ll i=1;i<=n;i++)printf("%lld/%lld\n",a[i].a,a[i].b);
    return 0;
}
null him

超了七个测试点

null him

怎么错了