zoukankan      html  css  js  c++  java
  • 【codewar-6kyu】Vasya

    ##题目描述

    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 single10050 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.

    Examples:

    1 ### Python ###
    2 
    3 tickets([25, 25, 50]) # => YES 
    4 tickets([25, 100]) # => NO. 

    ## 思路分析

    在这倒编码毫无难度纯看逻辑的题上,居然卡了半天,整个人都不好了,没好好读题没好好思考,让我去死一死

    卖25块一张的票,可能会收到25、50、100的钱;

    售票员不带零钱,面对什么样的队伍才能找得开零钱,全卖得了票呢?

    要按顺序卖票!!

    收的钱就留下了!!

    25开心手下;50必须找25;100优先找50,没有就找3张25(当然优先找50啦!50的只能找给100的,25还得尽量留着给50的呢!在这儿卡了是不是傻……)

    ## 代码解析

    Python:

     1 def tickets(people):
     2     n25 = n50 = n100 = 0
     3     for e in people:
     4         if   e==25            : n25+=1
     5         elif e==50            : n25-=1; n50+=1
     6         elif e==100 and n50>0 : n25-=1; n50-=1
     7         elif e==100 and n50==0: n25-=3
     8         if n25<0 or n50<0:
     9             return 'NO'
    10     return 'YES'

    就是简简单单按照收钱找钱的过程来就好了,少年不要想太多。

    ________你所记的,都是假的。
  • 相关阅读:
    开发网站邮件发送模块
    HttpModule的Init事件
    一个产品留言统计查寻的分析比较
    Js中清空文件上传字段(input type=file )
    Asp.net生成Excel报表
    jQuery与开发的相关js文件包含顺序
    trycatch 与 Response.End()
    asp.net2.0中的Usercontrol动态创建
    客户javascript端验证图片文件大小与规格使用Image对象
    JQuery 常用代码收集
  • 原文地址:https://www.cnblogs.com/pudding-ai/p/5824068.html
Copyright © 2011-2022 走看看