[acm]HDOJ 2673 shǎ崽 OrOrOrOrz

此博客展示了如何使用C++实现交替输出两个已排序数组的方法。

题目地址:

http://acm.hdu.edu.cn/showproblem.php?pid=2673

拍两次序,交替输出


 

 

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<cstdio>
 4 using namespace std;
 5 #define MAX_NUMBER 10000
 6 bool myfunction1 (int i,int j) { return (i<j); }
 7 bool myfunction2 (int i,int j) { return (i>j); }
 8 int number[2][MAX_NUMBER];
 9 int main()
10 {
11     //freopen("input.txt","r",stdin);
12     int n,tmp,count=0,index,flag;
13     while(cin>>n && n!=0)
14     {
15         for(int i=0;i<n;i++)
16         {
17             cin>>tmp;
18             number[0][i]=number[1][i]=tmp;
19         }
20         sort(number[0],number[0]+n,myfunction1);
21         sort(number[1],number[1]+n,myfunction2);
22         index=count=0;
23         flag=0;
24         while(index<n && count<n)
25         {
26             if(flag) cout<<" ";
27             if(count<n) {cout<<number[1][index];count++;}
28             if(count<n) {cout<<" "<<number[0][index];index++;count++;}
29             flag=1;
30         }
31     }
32     return 0;
33 }

 

转载于:https://www.cnblogs.com/panweishadow/p/3926877.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值