首页 技术 正文
技术 2022年11月18日
0 收藏 391 点赞 3,342 浏览 1690 个字

Why Males And Females Apart?

Time Limit: 2000/1000ms (Java/Others)

Problem Description:

In so many occasions, we can find that males and females standing by separately without any rules. So GG is considering whether we can find a way to eliminate the gender gap by sort all men and women in a row.Given a sequence A[1],A[2],A[3]......A[n],which means the heights of students. A[i]<0 means ith student is a girl,otherwise, ith student is a boy.Note that every elements in the sequence is distinct,which means there are not 2 elements having the same absolute value.And your job is to sort the students with their heights from low to high.
译文:在很多场合,我们可以发现那些男性和女性没有任何规则地分开站立。因此,GG正在考虑我们是否能够通过连续排列所有男性和女性来找到消除性别差距的方法。给定一个序列A [1],A [2],A [3] ...... A [n],这意味着学生的高度。A [i] <0表示第i个学生是女孩,否则第i个学生是男孩。注意序列中的每个元素都是不同的,这意味着没有2个元素具有相同的绝对值。并且您的工作是对学生的高度从低到高。

Input:

The input contains many tests.Each test case starts with a single line contains a single integer N(1<=N<=100),which means the number of students.Then a single line contains N integers which are the heights of students.The absolute value of each element is less than 200.
译文:输入包含许多测试。每个测试用例以单行开始,包含一个整数N(1 <= N <= 100),这意味着学生的数量。然后单行包含N个整数,这是学生的高度。每个元素的绝对值小于200。

Output:

For each test case,output all the integers separeted by a space after sort them as required.
译文:对于每个测试用例,根据需要对所有按空格分隔的整数进行排序。

Sample Input:

3
160 170 180
3
159 -171 -160

Sample Output:

160 170 180
159 -160 -171
解题思路:水题!!!用flag标记一下男女,真值为男,假值为女,然后结构体存放的全是正数,按从小到大排序,输出的时候如果flag是假值,前面加个负号就可以了,水过!
AC代码:
 #include<bits/stdc++.h>
using namespace std;
struct NODE{
bool flag;
int height;
}node[];
bool cmp(NODE x,NODE y){return x.height<y.height;}
int main()
{
int n,x;
while(cin>>n){
for(int i=;i<n;++i){
cin>>x;
if(x<){node[i].flag=false;x=-x;}
else node[i].flag=true;
node[i].height=x;
}
sort(node,node+n,cmp);
for(int i=;i<n;++i){
if(!node[i].flag)cout<<'-';
cout<<node[i].height<<(i!=n-?' ':'\n');
}
}
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,088
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,564
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,413
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,186
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,822
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,905