编程题:超市排队【难度:2级】--景越Python编程训练之挑战1000道Python面试题(含答案)

超市排队【难度:2级】:

超市有自助结账的队列。您的任务是编写一个函数来计算所有客户签出所需的总时间!

###输入

  • customers:表示队列的正整数数组。每个整数代表一个客户,其值是他们签出所需的时间。
  • n:正整数,结账数量。

###输出
该函数应返回一个整数,即所需的总时间。


##重要
请查看下面的示例和说明,以确保您正确理解任务:)


### 例子

queueTime([5,3,4],1)
//应该返回12
//因为当有1个时,总时间就是时间的总和

queueTime([10,2,3,3],2)
//应该返回10
//因为这里n = 2,而第二,第三和第四人在
//队列在第一个人完成之前完成。

queueTime([2,3,10],2)
//应该返回12
queue_time([5,3,4],1)
#应该返回12
#因为当n = 1时,总时间只是时间的总和

queue_time([10,2,3,3],2)
#应该返回10
#因为这里n = 2,而第二,第三和第四人在
#rief在第一个人完成之前完成。

queue_time([2,3,10],2)
#应该返回12
queue_time([5,3,4],1)
#应该返回12
#因为当n = 1时,总时间只是时间的总和

queue_time([10,2,3,3],2)
#应该返回10
#因为这里n = 2,而第二,第三和第四人在
#rief在第一个人完成之前完成。

queue_time([2,3,10],2)
#应该返回12
queueTime(std :: vector  {5,3,4},1)
//应该返回12
//因为当n = 1时,总时间只是时间的总和

queueTime(std :: vector  {10,2,3,3},2)
//应该返回10
//因为这里n = 2,而第二,第三和第四人在
//队列在第一个人完成之前完成。

queueTime(std :: vector  {2,3,10},2)
//应该返回12

###澄清

*只有一个队列服务很多,并且
 *队列的顺序永远不会改变,和
 *队列中的前面人员(即数组矩阵/列表中的第一个元素)一旦变为空闲就进入一个直到。

注:您应该假设所有测试输入都是有效的,如上所述。

附:这个kata的情况可以比作与线程池更加计算机科学相关的想法,与同时运行多个进程有关:https://en.wikipedia.org/wiki/Thread_pool

英文原题:

There is a queue for the self-checkout tills at the supermarket. Your task is write a function to calculate the total time required for all the customers to check out!

input

  • customers: an array of positive integers representing the queue. Each integer represents a customer, and its value is the amount of time they require to check out.
  • n: a positive integer, the number of checkout tills.

output

The function should return an integer, the total time required.


Important

Please look at the examples and clarifications below, to ensure you understand the task correctly


Examples

queueTime([5,3,4], 1)
// should return 12
// because when there is 1 till, the total time is just the sum of the times

queueTime([10,2,3,3], 2)
// should return 10
// because here n=2 and the 2nd, 3rd, and 4th people in the 
// queue finish before the 1st person has finished.

queueTime([2,3,10], 2)
// should return 12
queue_time([5,3,4], 1)
# should return 12
# because when n=1, the total time is just the sum of the times

queue_time([10,2,3,3], 2)
# should return 10
# because here n=2 and the 2nd, 3rd, and 4th people in the 
# queue finish before the 1st person has finished.

queue_time([2,3,10], 2)
# should return 12
queue_time([5,3,4], 1)
# should return 12
# because when n=1, the total time is just the sum of the times

queue_time([10,2,3,3], 2)
# should return 10
# because here n=2 and the 2nd, 3rd, and 4th people in the 
# queue finish before the 1st person has finished.

queue_time([2,3,10], 2)
# should return 12
queueTime(std::vector<int>{5,3,4}, 1)
// should return 12
// because when n=1, the total time is just the sum of the times

queueTime(std::vector<int>{10,2,3,3}, 2)
// should return 10
// because here n=2 and the 2nd, 3rd, and 4th people in the 
// queue finish before the 1st person has finished.

queueTime(std::vector<int>{2,3,10}, 2)
// should return 12

Clarifications

  • There is only ONE queue serving many tills, and
  • The order of the queue NEVER changes, and
  • The front person in the queue (i.e. the first element in the array/list) proceeds to a till as soon as it becomes free.

N.B. You should assume that all the test input will be valid, as specified above.

P.S. The situation in this kata can be likened to the more-computer-science-related idea of a thread pool, with relation to running multiple processes at the same time: https://en.wikipedia.org/wiki/Thread_pool

最佳答案合集(多种解法):

点击查看答案

更多关联题目:

单词搜索网格【难度:3级】–景越Python编程训练之挑战1000道Python面试题(含答案)
Krazy King二十一点【难度:3级】–景越Python编程训练之挑战1000道Python面试题(含答案)
降序排列【难度:1级】–景越Python编程训练之挑战1000道Python面试题(含答案)

免责申明:

本博客所有编程题目及答案均收集自互联网,主要用于供网友学习参考,如有侵犯你的权益请联系管理员及时删除,谢谢

你可能感兴趣的:(编程题:超市排队【难度:2级】--景越Python编程训练之挑战1000道Python面试题(含答案))