【问题标题】:Trouble writing basic pseudocode编写基本伪代码时遇到问题
【发布时间】:2018-03-27 13:17:07
【问题描述】:

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

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

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

【问题讨论】:

  • 你能在你的文件中提供一个示例数据吗?

标签: algorithm pseudocode


【解决方案1】:

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

假设有一个包含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.

希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-23
    • 1970-01-01
    • 2018-03-01
    相关资源
    最近更新 更多