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

边栏推荐
- Implementation of code scanning login
- Comment supprimer le crosstalk SiC MOSFET?
- Expérience d'optimisation SQL: de 30248 secondes à 0001 secondes
- Boundary value analysis method for learning basic content of software testing (2)
- Fire fighting work and measures in Higher Vocational Colleges
- How to implement two factor authentication MFA based on RADIUS protocol?
- 买卖股票费用计算
- A - Bi-shoe and Phi-shoe
- Basic operation of PMP from applying for the exam to obtaining the certificate, a must see for understanding PMP
- 电子元器件销售ERP管理系统哪个比较好?
猜你喜欢

JMeter -- interface test 1

Characteristics and prevention of electrical fire

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

containerd1.5.5的安装

Fire fighting work and measures in Higher Vocational Colleges

SQL注入之文件读写

How to solve the problem of high concurrency and seckill

JMeter -- interface test 2

Valentine's Day - VBS learning (sentences, love words)
![[big case] Xuecheng online website](/img/40/beec3ba567f5a372899bb58af0d05a.png)
[big case] Xuecheng online website
随机推荐
SQL injection file read / write
网上炒股开户安不安全?
Calculation of stock purchase and sale expenses
Resource scheduling and task scheduling of spark
[.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
[untitled]
SQL optimization experience: from 30248 seconds to 0.001 seconds
Test cases for learning the basic content of software testing (II)
Implementation of single sign on
Using transform:scale causes the page mouse hover event to disappear
I want to register my stock account online. How do I do it? Is online account opening safe?
Construire le premier réseau neuronal avec pytorch et optimiser
買賣股票費用計算
break database---mysql
Common tools for interface testing --postman
STL -- binder
Avframe Memory Management API
Deployment of MySQL database in Linux Environment
Quickly understand JVM structure and working principle
Integer partition