problemscpp
A collection of my answers to algorithm problems in c++.
Public 成员函数 | Private 属性 | 所有成员列表
leetcode::design_underground_system::UndergroundSystem类 参考

#include <leetcode.h>

Public 成员函数

 UndergroundSystem ()=default
 
void checkIn (int id, const string &stationName, int t)
 通行卡 ID 等于 id 的乘客,在时间 t ,从 stationName 站进入 乘客一次只能从一个站进入 更多...
 
void checkOut (int id, const string &stationName, int t)
 通行卡 ID 等于 id 的乘客,在时间 t ,从 stationName 站离开 更多...
 
double getAverageTime (const string &startStation, const string &endStation)
 平均时间会根据截至目前所有从 startStation 站 直接 到达 endStation 站的行程进行计算,也就是从 startStation 站进入并从 endStation 离开的行程 从 startStation 到 endStation 的行程时间与从 endStation 到 startStation 的行程时间可能不同 在调用 getAverageTime 之前,至少有一名乘客从 startStation 站到达 endStation 站 更多...
 

Private 属性

unordered_map< int, pair< string, int > > records
 
unordered_map< string, unordered_map< string, vector< int > > > um
 

详细描述

在文件 leetcode.h3263 行定义.

构造及析构函数说明

◆ UndergroundSystem()

leetcode::design_underground_system::UndergroundSystem::UndergroundSystem ( )
default

成员函数说明

◆ checkIn()

void leetcode::design_underground_system::UndergroundSystem::checkIn ( int  id,
const string &  stationName,
int  t 
)

通行卡 ID 等于 id 的乘客,在时间 t ,从 stationName 站进入 乘客一次只能从一个站进入

在文件 leetcode.cpp9359 行定义.

9359{ records[id] = {stationName, t}; }
unordered_map< int, pair< string, int > > records
Definition: leetcode.h:3265

引用了 records.

◆ checkOut()

void leetcode::design_underground_system::UndergroundSystem::checkOut ( int  id,
const string &  stationName,
int  t 
)

通行卡 ID 等于 id 的乘客,在时间 t ,从 stationName 站离开

在文件 leetcode.cpp9360 行定义.

9360{ um[records[id].first][stationName].emplace_back(t - records[id].second); }
unordered_map< string, unordered_map< string, vector< int > > > um
Definition: leetcode.h:3264

引用了 records , 以及 um.

◆ getAverageTime()

double leetcode::design_underground_system::UndergroundSystem::getAverageTime ( const string &  startStation,
const string &  endStation 
)

平均时间会根据截至目前所有从 startStation 站 直接 到达 endStation 站的行程进行计算,也就是从 startStation 站进入并从 endStation 离开的行程 从 startStation 到 endStation 的行程时间与从 endStation 到 startStation 的行程时间可能不同 在调用 getAverageTime 之前,至少有一名乘客从 startStation 站到达 endStation 站

返回
从 startStation 站到 endStation 站的平均时间

在文件 leetcode.cpp9362 行定义.

9362 {
9363 int total = 0;
9364 for(const auto t: um[startStation][endStation]) {
9365 total += t;
9366 }
9367 return static_cast<double>(total) / um[startStation][endStation].size();
9368 }

引用了 um.

类成员变量说明

◆ records

unordered_map<int, pair<string, int> > leetcode::design_underground_system::UndergroundSystem::records
private

在文件 leetcode.h3265 行定义.

被这些函数引用 checkIn() , 以及 checkOut().

◆ um

unordered_map<string, unordered_map<string, vector<int> > > leetcode::design_underground_system::UndergroundSystem::um
private

在文件 leetcode.h3264 行定义.

被这些函数引用 checkOut() , 以及 getAverageTime().


该类的文档由以下文件生成: