当前位置:网站首页>保研机试备考十五:字符串处理 集大成者
保研机试备考十五:字符串处理 集大成者
2022-07-16 06:18:00 【Alkali!】
题目描述
https://www.acwing.com/problem/content/3409/
思路
这题没什么算法含量在里面,主要考察语法
这是个多维度排序问题
代码
#include<iostream>
#include<cstring>
#include<algorithm>
#include<sstream>
using namespace std;
const int N=10010;
string logs[N];
int n;
int main()
{
while(getline(cin,logs[n]))
{
if(logs[n].size()) n++;
else break;
}
//排序,得自己写排序的cmp比较函数
sort(logs,logs+n,[](string& a,string& b){
stringstream ssina(a),ssinb(b);
string sa[4],sb[4];
for(int i=0;i<4;i++)
//利用stringstream将字符串按空格分割
{
ssina>>sa[i];
ssinb>>sb[i];
}
//如果两个计算任务消耗的时间相同,则将开始执行时间早的计算任务排在前面。因为长度是固定的,两个被比较的部分长度一样,因而这里可以直接比较字典序
if(sa[3]==sb[3]) return sa[1]+sa[2]<sb[1]+sb[2];
double da,db;
//位数不同,利用sscanf提取出浮点数,再作比较
//因为sscanf是C库函数,不支持string,所有得先通过.c_str()转换成字符数组
sscanf(sa[3].c_str(),"%lf(s)",&da);
sscanf(sb[3].c_str(),"%lf(s)",&db);
return da<db;
});
//输出
for(int i=0;i<n;i++)
cout<<logs[i]<<endl;
return 0;
}
边栏推荐
- Comparison and summary of five deep learning models for time series prediction: from simulated statistical model to unsupervised model that can be pre trained
- A series of questions about candy
- Three cycle structure of Microcomputer Principle and technology interface experiment
- How to choose databases and tables and newsql?
- After 2000, he was hired as a special associate researcher of Nanjing University. He went to primary school at the age of 4 and was admitted to Nanjing University at the age of 14!
- The most points on a straight line
- Data agility, HTAP database determines both efficiency and life and death
- Reconstructing the geometric form of weight space with training set
- 分库分表和 NewSQL 到底怎么选?
- 求数据流中的中位数问题
猜你喜欢

I "bring salt" for tdengine! "High price" to recruit photographed developers

出海已成大势,技术如何赋能?| ArchSummit

分库分表和 NewSQL 到底怎么选?

小程序毕设作品之微信评选投票小程序毕业设计(8)毕业设计论文模板

Idea integration Gerrit plug-in

Hal firmware library

antd a-upload 多选multiple为ture时 限制上传个数

小程序毕设作品之微信评选投票小程序毕业设计(6)开题答辩PPT

关于mock第三方调用

Win11 system How to enable Net Framework 3.5?
随机推荐
STM32应用开发实践教程:基于 RS-485 总线的多机通信应用开发
STM32应用开发实践教程:具备交互功能的人机界面应用开发
XGBoostError: [10:19:14] C:\dev\libs\xgboost\src\objective\objective. cc:23:
真值与条件表达式
分库分表和 NewSQL 到底怎么选?
Fleet |「后台探秘」第4期:分布式事务
启动失败 Failed to determine a suitable driver class 问题解决方案
Family tree problem
网络安全实验:防火墙技术
压力测试工具(常用)和sendfile的过程
Chapter I environment configuration
One click VR panorama display
配置MaskRCNN环境吐槽(GeForce MX250+win10+tensorflow1.5.0 GPU版)
Conditional ternary operator...
Codeforces Round #805 A - G
ArraysList和LinkedList的区别
Design of hydrogen monitoring system based on single chip microcomputer (0491)
StoneDB 宣布开源,一体化实时 HTAP 架构为何是当前最优解
小程序毕设作品之微信评选投票小程序毕业设计(8)毕业设计论文模板
HAL 固件库