| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1591 人关注过本帖
标题:编译错误
只看楼主 加入收藏
根根本根
Rank: 2
来 自:上海
等 级:论坛游民
帖 子:64
专家分:15
注 册:2018-3-19
结帖率:62.5%
收藏
 问题点数:0 回复次数:6 
编译错误
http://noi.

06:整数奇偶排序
总时间限制: 1000ms 内存限制: 65536kB
描述
给定10个整数的序列,要求对其重新排序。排序要求:

1.奇数在前,偶数在后;

2.奇数按从大到小排序;

3.偶数按从小到大排序。

输入
输入一行,包含10个整数,彼此以一个空格分开,每个整数的范围是大于等于0,小于等于100。
输出
按照要求排序后输出一行,包含排序后的10个整数,数与数之间以一个空格分开。
样例输入
4 7 3 13 11 12 0 47 34 98
样例输出
47 13 11 7 3 0 4 12 34 98
来源
1873

#include <bits/stdc++.h>
using namespace std;
bool cmp1(int a,int b) {
    if(a>b) {
        return 1;
    }
    return 0;
}
int main() {
    int a[10]= {0},b[10]= {0},n,m;
    for(int i=0; i<10; i++) {
        int t;
        cin>>t;
        if(t%2==0) {
            b[m]=i;
            m++;
        } else {
            a[n]=i;
            n++;
        }
    }
    sort(a,&a[n]);
    sort(b,&b[m],a);
    for(int i=0; i<n; i++) {
        cout<<a[i]<<" ";
    }
    cout<<endl;
    for(int i=0; i<m; i++) {
        cout<<b[i]<<" ";
    }
    return 0;
}
搜索更多相关主题的帖子: 编译 整数 排序 要求 int 
2018-08-31 12:17
根根本根
Rank: 2
来 自:上海
等 级:论坛游民
帖 子:64
专家分:15
注 册:2018-3-19
收藏
得分:0 
找到问题了
 但是这样的代码还是2分
#include <bits/stdc++.h>
using namespace std;
bool cmp1(int a,int b) {
    if(a>b) {
        return 1;
    }
    return 0;
}
int main() {
    int a[10]= {0},b[10]= {0},n=0,m=0;
    for(int i=0; i<10; i++) {
        int t;
        cin>>t;
        if(t%2==0) {
            b[m]=t;
            m++;
        } else {
            a[n]=t;
            n++;
        }
    }
    sort(a,&a[n]);
    sort(b,&b[m],cmp1);
    for(int i=0; i<n; i++) {
        cout<<a[i]<<" ";
    }
    for(int i=0; i<m; i++) {
        cout<<b[i]<<" ";
    }
    return 0;
}
2018-08-31 12:27
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
收藏
得分:0 
如果你时间不够,就别学编程
等你有时间了,将题目中的“样例输入”输入你的程序中试试,看看是不是和“样例输出”一致。
2018-08-31 13:49
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
收藏
得分:0 
如果不考虑运行效率的话,就按照题目要求写个比较函数就行了
程序代码:
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;

inline bool cmp( unsigned a, unsigned b )
{
    return a%2==0 ? (b%2==0 ? a<b : false) : (b%2==0 ? true : a>b);
}

int main( void )
{
    unsigned buf[10];
    copy_n( istream_iterator<unsigned>(cin), 10, buf );
    sort( buf, buf+10, &cmp );
    copy( buf, buf+10, ostream_iterator<unsigned>(cout," ") );
}

如果考虑运行效率的话,……
2018-08-31 15:06
根根本根
Rank: 2
来 自:上海
等 级:论坛游民
帖 子:64
专家分:15
注 册:2018-3-19
收藏
得分:0 
#include <bits/stdc++.h>
using namespace std;
bool cmp1(int a,int b) {
    if(a>b) {
        return 1;
    }
    return 0;
}
int main() {
    int a[10]= {0},b[10]= {0},n=0,m=0;
    for(int i=0; i<10; i++) {
        int t;
        cin>>t;
        if(t%2==0) {
            b[m]=t;
            m++;
        } else {
            a[n]=t;
            n++;
        }
    }
    sort(b,&b[m]);
    sort(a,&a[n],cmp1);
    for(int i=0; i<n; i++) {
        cout<<a[i]<<" ";
    }
    for(int i=0; i<m; i++) {
        cout<<b[i]<<" ";
    }
    return 0;
}
2018-08-31 15:25
根根本根
Rank: 2
来 自:上海
等 级:论坛游民
帖 子:64
专家分:15
注 册:2018-3-19
收藏
得分:0 
  ×
 ×*×
* * *       通过的代码
  *
   
  *
2018-08-31 15:26
汉家萌妹子
Rank: 2
等 级:论坛游民
威 望:5
帖 子:56
专家分:74
注 册:2018-8-21
收藏
得分:0 
编译错误请把错误信息也贴出来
2018-09-03 21:26
快速回复:编译错误
数据加载中...
 
   



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

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