文章
9
粉丝
0
获赞
92
访问
1.8k
关键点:
1. istringstream 对 整串分割为 id date time consumeTime 对应四个参数
2. 耗时(consumeTime) 要存储为 double ,因为长度不固定,不能用字符串直接比较
3. 日期(date) 和时间(time) 可以拼接到一起,用字符串直接比较。
3.1 因为两个都是定长的,字符串按照字符(ASCII)表逐个比较,效果和分割后,用 int 比较效果一样。
4. sort 排序后输出。
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
using namespace std;
typedef struct Log{
string rawLog;
string id;
string date;
string time;
double consumeTime;
} Log;
int main(){
string temp;
vector<Log> logs;
while(getline(cin, temp) && !temp.empty()){
Log log;
log.rawLog = temp; // 原始字符串
istringstream iss(temp);
iss >> log.id >> log.date >> log.time >> log.consumeTime; // 解析后字符串
logs.push_back(log);
...
登录后发布评论
牛逼