| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1427 人关注过本帖
标题:bool cmp()函数种结构体做参数为什么能够省略struct
只看楼主 加入收藏
troyzyc
Rank: 1
等 级:新手上路
帖 子:108
专家分:0
注 册:2016-7-4
结帖率:56.6%
收藏
已结贴  问题点数:4 回复次数:1 
bool cmp()函数种结构体做参数为什么能够省略struct
#include<iostream>
#include<algorithm>
using namespace std;
const int M=1000005;

struct three
{
    double w;
    double v;
    double p;
}s[M];

bool cmp(three a,three b)  //这里我试验了下,写成bool cmp(struct three a,struct three b)也可以。为什么能够省略struct?我认为struct three这是不能分开的呀,就是表示一种类型。
{
    return a.p>b.p;
}

int main()
{
    int n;
    double m;
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
        cin>>s[i].w>>s[i].v;
        s[i].p=s[i].v/s[i].w;
    }
    sort(s,s+n,cmp);
   
    double sum=0.0;   
    for(int i=0;i<n;i++)
    {
        if(m>s[i].w)
        {
            sum+=s[i].v;
            m-=s[i].w;
        }
        else
        {
            sum+=m*s[i].p;
            break;
        }
    }
    cout<<sum<<endl;
   
    return 0;
}
搜索更多相关主题的帖子: bool struct int double sum 
2018-03-13 17:13
yangfrancis
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:贵宾
威 望:141
帖 子:1510
专家分:7661
注 册:2014-5-19
收藏
得分:4 
C不行,C++可以
2018-03-13 22:35
快速回复:bool cmp()函数种结构体做参数为什么能够省略struct
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020682 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved