当前位置:网站首页>1182:合影效果
1182:合影效果
2022-06-28 09:07: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;
}

边栏推荐
- Applet: traverse the value of an array in the list, which is equivalent to for= "list" list An item in comment
- [untitled]
- How to suppress SiC MOSFET crosstalk?
- How to implement two factor authentication MFA based on RADIUS protocol?
- [big case] Xuecheng online website
- Apache Doris 成为 Apache 顶级项目
- I want to register my stock account online. How do I do it? Is online account opening safe?
- Which is a better ERP management system for electronic component sales?
- From knowledge to wisdom: how far will the knowledge map go?
- APICloud携手三六零天御,助力企业守好App安全“第一关”
猜你喜欢

Error: `brew cask` is no longer a `brew` command. Use `brew <command> --cask` instead.

How to suppress SiC MOSFET crosstalk?

图解MySQL的binlog、redo log和undo log

From knowledge to wisdom: how far will the knowledge map go?

SQL optimization experience: from 30248 seconds to 0.001 seconds

rman备份报ORA-19809 ORA-19804

Installation of containerd1.5.5

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

Rich text - Test Case

JMeter -- interface test 1
随机推荐
学习阿里如何进行数据指标体系的治理
DEJA_ Vu3d - 052 of cesium feature set - Simulation of satellite orbit (high altitude) effect
What are the advantages of a differential probe over a conventional probe
从知识到智慧:知识图谱还要走多远?
Build the first neural network with pytoch and optimize it
How to implement two factor authentication MFA based on RADIUS protocol?
Which securities company is better and safer to choose when opening an account for the inter-bank certificate of deposit fund with mobile phone
Implement global double finger long press to return to the desktop
spark的资源调度和任务调度
rman备份报ORA-19809 ORA-19804
Mysql8.0 forgot the root password
Application of current limiting protector in preventing electrical fire in shopping malls
Error: `brew cask` is no longer a `brew` command. Use `brew <command> --cask` instead.
[untitled]
104. maximum depth of binary tree
如何抑制SiC MOSFET Crosstalk(串擾)?
How do I open an account on my mobile phone? Is it safe to open an account online now?
Redis5.0 slot migration, free play (single machine migration cluster)
Matlab tips (20) matrix analysis -- principal component regression
I want to register my stock account online. How do I do it? Is online account opening safe?