当前位置:网站首页>1182: group photo effect
1182: group photo effect
2022-06-28 09:07:00 【A program ape who smashes the keyboard】
1182: Group photo effectThe time limit : 1000 ms Memory limit : 65536 KB Submission number : 19707 Passing number : 11284 【 Title Description 】Xiao Yun and his friends went to climb Xiangshan , Intoxicated by the beautiful scenery , Take a group photo . If they stand in a row , All the boys are on the left ( From the perspective of the photographer ), And in the order from low to high, from left to right , All the girls are on the right , And in the order from high to low, from left to right , What is the effect of their group photo ( Everyone is different in height )? 【 Input 】The first line is the number of people n(2 <= n <= 40, And at least there is 1 A boy and 1 A girl ). Follow closely behind n That's ok , Enter a person's gender on each line ( male male Or female female) And height ( Floating point numbers , Unit meter ), The two data are separated by spaces . 【 Output 】n A floating point number , After the simulation stands in line , The height of everyone from left to right in the eyes of the photographer . Each floating-point number should be kept after the decimal point 2 position , Two adjacent numbers are separated by a single space . 【 sample input 】6
male 1.72
male 1.78
female 1.61
male 1.65
female 1.70
female 1.56【 sample output 】1.65 1.72 1.78 1.70 1.61 1.56 |
【 Ideas 】
and Last question equally , Just sort the children's shoes into men and women .
【CE Code 】
#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 Code 】
#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 Code 】
#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;// Determine gender
else c[y++]=a[i].m;// Put it in an array
}
for(int i=0;i<x;i++)// Sort
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;
}

边栏推荐
- Discussion on safety management of centralized maintenance construction site of substation under the mode of operation and maintenance
- 个人究竟如何开户炒股?在线开户安全么?
- Basic knowledge of hard disk (head, track, sector, cylinder)
- APICloud携手三六零天御,助力企业守好App安全“第一关”
- 数据挖掘建模实战
- Deployment of MySQL database in Linux Environment
- 买卖股票费用计算
- From knowledge to wisdom: how far will the knowledge map go?
- Build the first neural network with pytoch and optimize it
- [.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
猜你喜欢

SQL optimization experience: from 30248 seconds to 0.001 seconds

Resource scheduling and task scheduling of spark

【无标题】

containerd1.5.5的安装

Calcul des frais d'achat et de vente d'actions

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

【大案例】学成在线网站

Webrtc advantages and module splitting
![[cloud native | kubernetes] in depth understanding of pod (VI)](/img/ae/f16f5c090251ab603b88ddadff7eb3.png)
[cloud native | kubernetes] in depth understanding of pod (VI)

It only takes two steps to find the right PMP organization, one check and two questions
随机推荐
Power data
Loggerfactory uses log4j Parameter introduction of properties
Avframe Memory Management API
Almost union find (weighted union search)
Batch modify tables and sorting rules for fields in tables
How to suppress SiC MOSFET crosstalk?
DEJA_ Vu3d - 051 of cesium function set - perfect realization of terrain excavation
【大案例】学成在线网站
Common test method used by testers --- orthogonal method
Is it safe to open an account for mobile phone stock speculation?
玩玩sftp上传文件
Boundary value analysis method for learning basic content of software testing (2)
Play SFTP upload file
Apache Doris becomes the top project of Apache
Build the first neural network with pytoch and optimize it
买卖股票费用计算
用Pytorch搭建第一个神经网络且进行优化
Scenario method and error recommendation method for learning basic content of software testing (2)
How to solve the problem of high concurrency and seckill
Discussion on the practice of fire emergency lighting system in the field of building electrical design