Loading...

Във форума е въведено ограничение, което позволява на потребителите единствено да разглеждат публикуваните въпроси.

Sirakov4444 avatar Sirakov4444 11 Точки

two inputs at a time

Здравейте,

 

Решавам задача, която изисква да се вкарат няколко inputs на 2 отделни реда, как е възможно да стане това?

Input deals:

  • 2 for 3 - ["apple", "banana", "tomato"]
  • buy 1 get 1 half price - potato
  • "apple", "banana", "banana", "potato", "tomato", "banana", "potato"

Трябва да извлеча  1.- промоция 2за3, 2.- String array и на следващия ред 3.- String след тирето(potato)  и накрая String масив ....

 

 

Моля за споделяне на някакви начини, благодаря Ви предварително.

0
JavaScript Applications
MartinBG avatar MartinBG 4803 Точки

От въпроса не е много ясно какви точно са входните данни и какво трябва да се парсне от тях за да бъда конкретен в отговора си, но като цяло това са неща, които се учат в Programming Basics - получаване на текст и сплитването му по някакви критерии. Със знанията от Fundamentals може да се използва и RegEx

Дали входните данни са на 1, 2 или повече реда не променя нищо в горната методология.

0
13/02/2023 14:59:20
Sirakov4444 avatar Sirakov4444 11 Точки

@MartinBG

Съжалявам, моя грешка, ето я пълната задачка: Все пак мисля, че се изискват няколко входа, но още не съм сигурен.

 

 

## "Exercise" Requirements

- Create a basic Groceries Shop till which can `scan` fruits and vegetables of different types, producing a numeric result/bill in the end. Assume the currency is called `aws` and there is `100 cloud ('c' for short)` in 1 aws
- Apart from simply adding the value of each product, the till should contain logic for the following special deals:
  - `2 for 3` - for a given selection of items (customer buys 3 items but only pays for the value of 2 of them, the cheapest one is free). In case there are more than 3 items that are included in the `2 for 3` deal, the first 3 items are included.
    Example Deal ["banana", "orange", "tomato"], example items scanned ["banana", "orange", "orange", "tomato"] - the tomato is not included in the discount (the cheaper of `banana` or `orange` will be subtracted)
  - `buy 1 get 1 half price` - for a given selection of items (if the customer buys a given product under such offer, they receive a 50% reduction in the price of a second item of the same type)
- The till should be `programmable` so that whoever runs it can define 2 inputs:
  - The list of items supported by the till - each item with a given "price", "name"
  - Once a new item is added to the till, the administrator should be able to add it to any of the 2 special deals defined above
  - You should be able to scan a list of items and see the end price (any special deal discounts should be subtracted)

### Example:

Input groceries:

| Product | Price |
| ------- | :---: |
| apple   |  50c  |
| banana  |  40c  |
| tomato  |  30c  |
| potato  |  26c  |

Input deals:

- `2 for 3` - ["apple", "banana", "tomato"]
- `buy 1 get 1 half price` - potato

Example scanned customer basket: "apple", "banana", "banana", "potato", "tomato", "banana", "potato"

Expected Output: `1 aws and 99 clouds`
Explanation:

The items are processed(Scanned) in order:

- "apple", "banana", "banana" are picked up for the `2 for 3` deal and 1 of the bananas is free - total cost `90c`

- "potato", "tomato", "banana", "potato" are left. There is a `buy 1 get 1 half price` for potatoes, meaning the second potato will be half price (13c) so it will be `39c` for both

- The other 2 items scanned `tomato` and `banana` are not part of any deals so they are charged their basic price `70c` total

The total amount the is equal to: `90c + 39c + 70c = 1 aws and 99 clouds` (199 clouds = 1.99 aws)

0
14/02/2023 19:38:09
Можем ли да използваме бисквитки?
Ние използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Можете да се съгласите с всички или част от тях.
Назад
Функционални
Използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Използваме „сесийни“ бисквитки, за да Ви идентифицираме временно. Те се пазят само по време на активната употреба на услугите ни. След излизане от приложението, затваряне на браузъра или мобилното устройство, данните се трият. Използваме бисквитки, за да предоставим опцията „Запомни Ме“, която Ви позволява да използвате нашите услуги без да предоставяте потребителско име и парола. Допълнително е възможно да използваме бисквитки за да съхраняваме различни малки настройки, като избор на езика, позиции на менюта и персонализирано съдържание. Използваме бисквитки и за измерване на маркетинговите ни усилия.
Рекламни
Използваме бисквитки, за да измерваме маркетинг ефективността ни, броене на посещения, както и за проследяването дали дадено електронно писмо е било отворено.