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 ;
}

ACM_绝对值排序的更多相关文章

  1. HDOJ2020绝对值排序

    绝对值排序 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  2. (qsort)绝对值排序

    绝对值排序 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Subm ...

  3. 【ACM】hdu_zs3_1003_绝对值排序_201308100742

    绝对值排序 Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)Total Submissi ...

  4. 【ACM】hdu_2020_绝对值排序_201308050929

    绝对值排序 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  5. HDU_2020——按绝对值排序

    Problem Description 输入n(n<=100)个整数,按照绝对值从大到小排序后输出.题目保证对于每一个测试实例,所有的数的绝对值都不相等.   Input 输入数据有多组,每组占 ...

  6. UVA 11039-Building designing【贪心+绝对值排序】

    UVA11039-Building designing Time limit: 3.000 seconds An architect wants to design a very high build ...

  7. HDU 2020 绝对值排序

    http://acm.hdu.edu.cn/showproblem.php?pid=2020 Problem Description 输入n(n<=100)个整数,按照绝对值从大到小排序后输出. ...

  8. HDU2020——绝对值排序(java实现,使用map)

    Question Description Input Output Sample Input Sample Output 解题思路简述: 在接收每一个数组的过程中,将负数及其绝对值以键值对的形式存入m ...

  9. ACM_绝对值

    100块钱都不给我 Time Limit: 2000/1000ms (Java/Others) Problem Description: 今天是广财的ACM周赛,小光来到广财实验楼,想来蹭一下素拓分( ...

随机推荐

  1. Android写入到mysql里的中文总是乱码?

    中文编码的问题总是让人头疼,之前在python爬虫就折腾得死去活来,现在写app又是这样. 总结下来,就是三点吧: 数据库: 确定字符编码是utf8, collate: utf8_general_ci ...

  2. 【tips】xadmin - django第三方后台管理系统

    Django 为大家提供了一个完善的后台管理系统—admin,但是这个后台管理系统总体来说不太适合国人的习惯,所以有大神就使用 bootstrap 和 jQuery,为我们开发了一个第三 方的 Dja ...

  3. Pygame游戏开发入门(1)-开发框架

    pygame库的安装 pip install pygame pygame最小开发框架 #Pygame Hello World Game import pygame,sys #引入pygame和sys( ...

  4. Authors and instutes in MCT

    Authors and instutes in MCT Table of Contents 1. Authors and Institutes 1.1. Industry 1 Authors and ...

  5. concepts in Turbulent Flow

    Table of Contents 1. Concepts/Glossary 1.1. Turbulent eddy viscosity ,μt 1.2. Turbulent kinetic ener ...

  6. 我安装android studio的过程与经历

    虽然android studio已经出来两年多了,但是我一直都没真正用过.之前用Eclipse还算用得挺好.我并不是一个专职的android开发者,我是个游戏开发者,打包的时候要用到android.不 ...

  7. Java MyBatis 插入数据库返回主键--insertSelective这样就不用每次到数据库里面查询了

    insertSelective---Java MyBatis 插入数据库返回主键--insertSelective这样就不用每次到数据库里面查询了 https://www.cnblogs.com/xi ...

  8. HDU 1130

    题目大意 给定节点数 , 求通过这么多个节点能得到的二叉树的组成方式 用卡特兰数解决 f[n] = (4*n-2) * f[n-1] / (n+1); 递归不断解决 /** * @(#)Main.ja ...

  9. [luoguP1854] 花店橱窗布置(DP)

    传送门 f[i][j] 表示前 i 盆花,放到前 j 个花盆中的最优解 pre[i][j] 记录前驱 代码 #include <cstdio> #include <cstring&g ...

  10. hdu 2224 双调欧几里得旅行商问题tsp

    /* 题意:平面上n个点,确定一条连接各点的最短闭合旅程且每个点仅用一次.这个解的一般形式为NP的(在多项式时间内可以求出) 建议通过只考虑双调旅程(bitonictour)来简化问题,这种旅程即为从 ...