问题标题: 酷町堂:2705拿错了?

0
0
已解决
被禁言 汪子晨
汪子晨
修练者
修练者

我的代码:

#include<iostream>
#include<algorithm>
using namespace std;
struct s{
    string name;
    int c,d,e;
    int sum() {return (c+d+e)/3;} 
}a[100000];
bool cmp(s k,s g){
    if(k.sum()!=g.sum())
        return k.sum()<g.sum();
        return k.c<g.c;
}
int main(){
    int f;
    cin>>f;
    for(int i=0;i<f;i++){
        cin>>a[i].name>>a[i].c>>a[i].d>>a[i].e; 
    }
    sort(a,a+f,cmp);
    for(int i=0;i<f;i++){
        if((a[i].c&&a[i].d&&a[i].e)!=0) {
            cout<<a[i].name<<" "<<a[i].c<<' '<<a[i].d<<" "<<a[i].e;
            break;
    }
    }
}

70……


0
已采纳
陈则霖
陈则霖
资深光能
资深光能
  •  奉上
  • double sum[1000000];
  • struct cut{ string s; int a; int b; int c;
  • }d[1000000];
  • int main() {
  • int n;
  • cin>>n;
  • for(int i=1;i<=n;i++){
  • cin>>d[i].s>>d[i].a>>d[i].b>>d[i].c;
  • }
  • int t=0; double sm=10000000; int f=0;
  • for(int i=1;i<=n;i++){
  • if(d[i].a!=0&&d[i].b!=0&&d[i].c!=0)
  • {
  • double m=(d[i].a+d[i].b+d[i].c)/3.0;
  • if(m<sm){
  • sm=m; f=i;
  • }
  • }
  • }
  • cout<<d[f].s<<" "<<d[f].a<<" "<<d[f].b<<" "<<d[f].c; return 0; }
0
0
0
0
丁勇智
丁勇智
中级守护
中级守护
  • 采纳我吧!采纳采纳我吧!我吧!采纳我吧!采纳我吧!采纳我吧!采纳我吧!采纳我吧!
  •  
  • #include<iostream>
  • #include<cstdio>
  • #include<cmath>
  • #include<string>
  • #include<algorithm>
  • using namespace std;
  • 结构体 xs{
  • 字符串 name;
  • 整形 t1,t2,t3;
  • 大伯 pj(){
  • return(t1+t2+t3)/3.0;
  • }
  • }a[65];
  • int main(){
  • 整形 n,pos;
  • double minn=0x3f3f3f3f;
  • 读入>>n;
  • 循环(int i=1;i<=n;i++){
  • 读入>>a[i].name>>a[i].t1>>a[i].t2>>a[i].t3;
  • 如果(a[i].pj()<minn&&a[i].t1!=0&&a[i].t2!=0&&a[i].t3!=0){
  • minn=a[i].pj(); pos=i;
  • }
  • }
  • 输出<<a[pos].name<<" "<<a[pos].t1<<" "<<a[pos].t2<<" "<<a[pos].t3;
  • return 0;
  • }
0
曹博扬
曹博扬
初级天翼
初级天翼

if(x.sum()!=0&&y.sum()!=0)

    return x.sum()<y.sum();

return x.sum()>y.sum();

结构体排序

 

0
0
我要回答