无法编写基本的伪代码

时间:2018-03-27 13:17:08

标签: algorithm pseudocode

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

我有一个数据集,其中包含 start end 两次出租车行程的时间(end_timestart_time)。我需要帮助编写一些伪码来计算这些行程中有多少次超过1小时。

duration一次只读取一个,只应在文件结束时才读取。

1 个答案:

答案 0 :(得分:0)

让我们试着通过一个例子来编写上述问题的算法。

假设有5end_timestart_time的文件,如下所示: -

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.

希望这有帮助!