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

边栏推荐
- [big case] Xuecheng online website
- Ffmpeg streaming fails to update header with correct duration
- 手机买同业存单基金开户选哪家证券公司比较好,比较安全呢
- I want to register my stock account online. How do I do it? Is online account opening safe?
- 使用transform:scale之后导致页面鼠标悬浮事件消失
- 华泰证券网上开户安全吗 办理流程是什么
- 【无标题】
- Tree
- Rich text - Test Case
- 【无标题】
猜你喜欢

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

如何抑制SiC MOSFET Crosstalk(串擾)?

"Jianzhi offer" -- Interview Question 4: finding two-dimensional arrays

买卖股票费用计算

使用transform:scale之后导致页面鼠标悬浮事件消失

How to solve the problem of port number occupation

SQL optimization experience: from 30248 seconds to 0.001 seconds

Data modeling based on wide table

Rman Backup Report Ora - 19809 Ora - 19804

Stock suspension
随机推荐
Expérience d'optimisation SQL: de 30248 secondes à 0001 secondes
Discussion on the improvement and application of the prepayment system in the management of electricity charge and price
Import and export of a single collection in postman
Three body attack (three-dimensional split plus two points)
为什么SELECT * 会导致查询效率低?
Potential safety hazards in elderly care facilities
Error: `brew cask` is no longer a `brew` command. Use `brew <command> --cask` instead.
Zhejiang energy online monitoring and management system
Comment supprimer le crosstalk SiC MOSFET?
Tree
Is it safe for Huatai Securities to open an account online? What is the handling process
Illustration of MySQL binlog, redo log and undo log
Basic content learning of software testing (I)
How to solve the problem of high concurrency and seckill
Power data
Copy & Deepcopy
From knowledge to wisdom: how far will the knowledge map go?
How to suppress SiC MOSFET crosstalk?
Decision table method for basic content learning of software testing (2)
理解IO模型