当前位置:网站首页>1182:合影效果
1182:合影效果
2022-06-28 09:06:00 【暴揍键盘的程序猿】
1182:合影效果时间限制: 1000 ms 内存限制: 65536 KB 提交数: 19707 通过数: 11284 【题目描述】小云和朋友们去爬香山,为美丽的景色所陶醉,想合影留念。如果他们站成一排,男生全部在左(从拍照者的角度),并按照从矮到高的顺序从左到右排,女生全部在右,并按照从高到矮的顺序从左到右排,请问他们合影的效果是什么样的(所有人的身高都不同)? 【输入】第一行是人数n(2 <= n <= 40,且至少有1个男生和1个女生)。 后面紧跟n行,每行输入一个人的性别(男male或女female)和身高(浮点数,单位米),两个数据之间以空格分隔。 【输出】n个浮点数,模拟站好队后,拍照者眼中从左到右每个人的身高。每个浮点数需保留到小数点后2位,相邻两个数之间用单个空格隔开。 【输入样例】6
male 1.72
male 1.78
female 1.61
male 1.65
female 1.70
female 1.56【输出样例】1.65 1.72 1.78 1.70 1.61 1.56 |
【思路】
和上题一样,把童鞋们分成男女来排序即可。
【CE代码】
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<string>
#include<vector>
using namespace std;
const int N=1e5+10;
inline int fread()
{
char ch=getchar();
int n=0,m=1;
while(ch<'0' or ch>'9')
{
if(ch=='-')m=-1;
ch=getchar();
}
while(ch>='0' and ch<='9')n=(n<<3)+(n<<1)+ch-48,ch=getchar();
return n*m;
}
int n,x,y;
double b[N],c[N];
struct node
{
double m;
char ch[N];
}a[N];
void _sort()
{
for(int i=0;i<x;i++)
for(int j=i+1;i<x;j++)
if(b[i]>b[j])swap(b[i],b[j]);
for(int i=0;i<y;i++)
for(int j=i+1;j<y;j++)
if(c[i]<c[j])swap(c[i],c[j]);
}
signed main()
{
n=fread();
for(int i=0;i<n;i++)
{
cin>>a[i].ch>>a[i].m;
if(strcmp(a[i].ch,"male")==0)b[x++]=a[i].m;
else c[y++]=a[i].m;
}
_sort();
for(int i=0;i<x;i++)cout<<fixed<<setprecision(2)<<b[i];
for(int i=0;i<y;i++)cout<<fixed<<setprecision(2)<<c[i];
return 0;
}
【RE代码】
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<string>
#include<vector>
using namespace std;
const int N=1e5+10;
inline int fread()
{
char ch=getchar();
int n=0,m=1;
while(ch<'0' or ch>'9')
{
if(ch=='-')m=-1;
ch=getchar();
}
while(ch>='0' and ch<='9')n=(n<<3)+(n<<1)+ch-48,ch=getchar();
return n*m;
}
int n,x,y;
double b[N],c[N];
struct node
{
double m;
char ch[20];
}a[N];
void _sort()
{
for(int i=0;i<x;i++)
for(int j=i+1;i<x;j++)
if(b[i]>b[j])swap(b[i],b[j]);
for(int i=0;i<y;i++)
for(int j=i+1;j<y;j++)
if(c[i]<c[j])swap(c[i],c[j]);
}
signed main()
{
n=fread();
for(int i=0;i<n;i++)
{
cin>>a[i].ch>>a[i].m;
if(strcmp(a[i].ch,"male")==0)b[x++]=a[i].m;
else c[y++]=a[i].m;
}
_sort();
for(int i=0;i<x;i++)cout<<fixed<<setprecision(2)<<b[i];
for(int i=0;i<y;i++)cout<<fixed<<setprecision(2)<<c[i];
return 0;
}
【AC代码】
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<string>
#include<vector>
using namespace std;
const int N=45;
inline int fread()
{
char ch=getchar();
int n=0,m=1;
while(ch<'0' or ch>'9')
{
if(ch=='-')m=-1;
ch=getchar();
}
while(ch>='0' and ch<='9')n=(n<<3)+(n<<1)+ch-48,ch=getchar();
return n*m;
}
int n,x,y;
double b[N],c[N];
struct node
{
double m;
char ch[N];
}a[N];
signed main()
{
n=fread();
for(int i=0;i<n;i++)
{
cin>>a[i].ch>>a[i].m;
if(strcmp(a[i].ch,"male")==0)b[x++]=a[i].m;//判断性别
else c[y++]=a[i].m;//存到数组里
}
for(int i=0;i<x;i++)//排序
for(int j=i+1;j<x;j++)
if(b[i]>b[j])
swap(b[i],b[j]);
for(int i=0;i<y;i++)
for(int j=i+1;j<y;j++)
if(c[i]<c[j])
swap(c[i],c[j]);
for(int i=0;i<x;i++)cout<<fixed<<setprecision(2)<<b[i]<<" ";
for(int i=0;i<y;i++)cout<<fixed<<setprecision(2)<<c[i]<<" ";
return 0;
}

边栏推荐
- centos mysql5.5配置文件在哪
- 为什么SELECT * 会导致查询效率低?
- How to solve the problem of high concurrency and seckill
- Redis5.0 slot migration, free play (single machine migration cluster)
- Build the first neural network with pytoch and optimize it
- MySQL8.0 忘记 root 密码
- Basic content learning of software testing (I)
- State machine program framework
- A - Bi-shoe and Phi-shoe
- Is it safe to open an account for mobile phone stock speculation?
猜你喜欢

How to suppress SiC MOSFET crosstalk?

APICloud携手三六零天御,助力企业守好App安全“第一关”

Characteristics and prevention of electrical fire

Large current and frequency range that can be measured by Rogowski coil

redis5.0的槽点迁移,随意玩(单机迁移集群)

Discussion on the practice of fire emergency lighting system in the field of building electrical design

用Pytorch搭建第一个神经网络且进行优化

MySQL8.0 忘记 root 密码

Almost union find (weighted union search)

Discussion on the improvement and application of the prepayment system in the management of electricity charge and price
随机推荐
From knowledge to wisdom: how far will the knowledge map go?
【无标题】
spark的资源调度和任务调度
Application of current limiting protector in preventing electrical fire in shopping malls
Zhejiang energy online monitoring and management system
Android studio interview preparation
我想网上注册股票开户,如何操作?在线开户安全么?
手机买同业存单基金开户选哪家证券公司比较好,比较安全呢
Implementation of single sign on
Is it safe for CICC fortune to open an account? How much do you charge?
[.Net6] GRP server and client development cases, as well as the access efficiency duel between the minimum API service, GRP service and traditional webapi service
Calcul des frais d'achat et de vente d'actions
理解IO模型
I want to register my stock account online. How do I do it? Is online account opening safe?
DEJA_ Vu3d - 051 of cesium function set - perfect realization of terrain excavation
Trailing Zeroes (II)
Chrome devtools
Goldbach`s Conjecture
Power data
Illustration of MySQL binlog, redo log and undo log