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

边栏推荐
- 如何抑制SiC MOSFET Crosstalk(串擾)?
- Three body attack (three-dimensional split plus two points)
- Redis5.0 slot migration, free play (single machine migration cluster)
- 数据挖掘建模实战
- Potential safety hazards in elderly care facilities
- 网上炒股开户安不安全?
- Webrtc advantages and module splitting
- APICloud携手三六零天御,助力企业守好App安全“第一关”
- 个人究竟如何开户炒股?在线开户安全么?
- I want to register my stock account online. How do I do it? Is online account opening safe?
猜你喜欢
JMeter -- interface test 2
Loggerfactory uses log4j Parameter introduction of properties
What are the advantages of a differential probe over a conventional probe
Construire le premier réseau neuronal avec pytorch et optimiser
STL - inverter
【大案例】学成在线网站
買賣股票費用計算
Common tools for interface testing --postman
redis5.0的槽点迁移,随意玩(单机迁移集群)
Fire fighting work and measures in Higher Vocational Colleges
随机推荐
SQL 优化经历:从 30248秒到 0.001秒的经历
Copy & Deepcopy
redis5.0的槽点迁移,随意玩(单机迁移集群)
Which securities company is better and safer to choose when opening an account for the inter-bank certificate of deposit fund with mobile phone
[big case] Xuecheng online website
【大案例】学成在线网站
华泰证券网上开户安全吗 办理流程是什么
个人究竟如何开户炒股?在线开户安全么?
What are the advantages of a differential probe over a conventional probe
图解MySQL的binlog、redo log和undo log
Implementation of single sign on
Is it safe to open an account for mobile phone stock speculation?
Comment supprimer le crosstalk SiC MOSFET?
centos mysql5.5配置文件在哪
Understanding the IO model
Analysis of prepaid power purchase device
Protection range and optimization of motor protector for hoist equipment
手机炒股开户安不安全?
How do individuals open accounts to speculate in stocks? Is online account opening safe?
罗氏线圈工作原理