当前位置:网站首页>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;
}

边栏推荐
- Apiccloud, together with 360 Tianyu, helps enterprises keep the "first pass" of APP security
- Potential safety hazards in elderly care facilities
- Calcul des frais d'achat et de vente d'actions
- 实现全局双指长按返回桌面
- High rise building fire prevention
- How do I open an account on my mobile phone? Is it safe to open an account online now?
- SQL 優化經曆:從 30248秒到 0.001秒的經曆
- Use of Jasper soft studio report tool and solution of thorny problems
- Using transform:scale causes the page mouse hover event to disappear
- 状态机程序框架
猜你喜欢

基于宽表的数据建模

Rman Backup Report Ora - 19809 Ora - 19804

Using transform:scale causes the page mouse hover event to disappear

Lilda low code data large screen, leveling the threshold of data application development

用Pytorch搭建第一個神經網絡且進行優化

SQL 優化經曆:從 30248秒到 0.001秒的經曆

How to solve the problem of high concurrency and seckill

containerd1.5.5的安装

Application of energy management system in iron and steel enterprises

【大案例】学成在线网站
随机推荐
Fire safety hazards
Which is a better ERP management system for electronic component sales?
Using transform:scale causes the page mouse hover event to disappear
中金财富开户安全吗?怎么收费?
A - deep sea exploration
Boundary value analysis method for learning basic content of software testing (2)
STL -- binder
[big case] Xuecheng online website
Webrtc advantages and module splitting
Almost union find (weighted union search)
Copy & Deepcopy
Discussion on the improvement and application of the prepayment system in the management of electricity charge and price
Loggerfactory uses log4j Parameter introduction of properties
Analysis of prepaid power purchase device
Scenario method and error recommendation method for learning basic content of software testing (2)
Apache Doris 成为 Apache 顶级项目
Common test method used by testers --- orthogonal method
State machine program framework
Goldbach`s Conjecture
Operating principle of Rogowski coil