编写基本伪代码时遇到问题



我需要帮助编写一些基本的伪代码。

我有一个数据集,其中包含出租车行程的开始结束时间(以分钟为单位)(end_timestart_time)。我需要帮助编写一些伪代码来计算这些行程中有多少次大于 1 小时。

一次读取一个duration,并且只应在到达文件末尾之前读取。

让我们尝试通过一个例子为上述问题编写一个算法。

假设有一个文件包含end_timestart_time5条目,如下所示:

1. 09:00 am - 10:05 am
2. 11:00 am - 11:15 am  
3. 12:00 pm - 12:30 pm
4. 15:00 pm - 18:00 pm
5. 07:00 am - 07:10 am

由于帖子没有提供示例数据,我假设数据看起来与我上面写的类似,其中first time是我们start_timesecond time是我们end_time

现在我们的算法看起来像这样:

Step 1. Load the file which has data. Also create a global variable to store count and initialize it to zero.
Step 2. Start Reading the file line by line and store each line in a temporary variable.
Step 3. Parse the line i.e split the line in the above example based on ' ' (space).
Step 4. Once we get the start and end time while parsing the line, calculate the time difference and store this difference in a variable called diff_time.
Step 5. if (diff_time > 1 hour) { count++; }
Step 6. Print the count.

希望这有帮助!

最新更新