美文网首页
习题16:卖票

习题16:卖票

作者: 今年说话算话 | 来源:发表于2017-02-22 13:12 被阅读0次

Description:

The new "Avengers" movie has just been released! There are a lot of people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 dollars bill. A "Avengers" ticket costs 25 dollars.

Vasya is currently working as a clerk. He wants to sell a ticket to every single person in this line.

Can Vasya sell a ticket to each person and give the change if he initially has no money and sells the tickets strictly in the order people follow in the line?

Return YES, if Vasya can sell a ticket to each person and give the change. Otherwise return NO.

def tickets(people):
    #giving a change: change 25$ for 50$ and change 50$+25$ or 25$*3 for 100$
    change = {
        25: 0,
        50: 0,
    }
    for money in people:
        if money == 25:
            change[25] += 1
        elif money == 50:
            change[50] += 1
            change[25] -= 1
        else:
            if change[50] >= 1:
                change[50] -= 1
                change[25] -= 1
            else:
                change[25] -= 3
        if change[25] < 0:
            return 'NO'
    return 'YES'

相关文章

  • 习题16:卖票

    Description: The new "Avengers" movie has just been relea...

  • 【Python爬虫】-第二周 习题 13-17 (解包,参数,文

    习题 13-17 (解包,参数,文件读写等) 习题13 习题14 习题15 习题16 16-1 16-2 习题17...

  • 【Python爬虫】-笨办法学 Python 习题13-17

    习题13 习题14 习题15 习题16 习题17

  • 量子学派:热力学第二定律

    第16天第16个公式 阅读内容 课后习题

  • 卖票

    Runnable卖票 publicclass Main { publicstaticvoid main(Str...

  • 卖票

    今天上票房,游客真的很多,昨天的计划就是今天专注卖票,争取不差钱,争取体验到心流状态! 今天其实状态...

  • 真会卖票

    真会卖票 文/高峰青青草 因为连续下过阵雨,所以高温已降。一大早,我们一家人就趁着凉爽去大明湖游玩。 还没到大明湖...

  • 卖票员

    小时候坐公交车,最喜欢站在卖票员阿姨旁边,看着卖票员整理纸币,那时候就想等我长大了,我也要做卖票员,每天都要把折角...

  • 多线程

    进程 线程 多线程卖票案例

  • 关于买票 卖票

    这两天也有很多人来问我关于哥哥们见面会的门票,有人问我很欢迎,当然了问了不能接受价格的我们也可以做个朋友。 关于我...

网友评论

      本文标题:习题16:卖票

      本文链接:https://www.haomeiwen.com/subject/huxmwttx.html