C++ Language

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

C++ Language

An e-commerce company specializes in cards with sports figures on them. Each sport has different
categories of cards. For instance, there might be more desirable cards with the most popular sports
personalities, others with small pieces of a player's jersey attached, and so on. They have a number of each
category of card and want to make some number of packets greater than 1 that each contain equal
numbers of each type of card. To do this, they will add more cards of each type until each type can be
divided equally among some number of packets. Determine the minimum number of additional cards
needed to create a number of packets with equal type distribution.
Example
n=5
cardTypes = [4, 7, 5, 11, 15]
In order to make 2 matching packets, the following numbers of additional cards of each type must be
added: [0, 1, 1, 1, 1]. This sums to 4 additional cards. The numbers of cards are [4, 8, 6, 12, 16] and they can
be divided evenly among 2 packets. If 3 packets are created, an additional [2, 2, 1, 1, 0] cards are needed,
sum = 6 items. This yields quantities [6, 9, 6, 12, 15]. Any number of packets > 2 can be created, but creating
2 packets requires the minimum number of additional cards.
Function Description
Complete the function cardPackets in the editor below.
cardPackets has the following parameter(s):
int cardTypes[n]: the quantity available of card type
Returns
int: the minimum number of additional cards to add
Constraints
• 1sns10²
• 1 ≤ card Types[i] ≤ 500
Input Format For Custom Testing
The first line contains an integer, n, the size of the card Types array.
Each line / of the n subsequent lines (where Osi<n) contains an integer cardTypes[i].
Transcribed Image Text:An e-commerce company specializes in cards with sports figures on them. Each sport has different categories of cards. For instance, there might be more desirable cards with the most popular sports personalities, others with small pieces of a player's jersey attached, and so on. They have a number of each category of card and want to make some number of packets greater than 1 that each contain equal numbers of each type of card. To do this, they will add more cards of each type until each type can be divided equally among some number of packets. Determine the minimum number of additional cards needed to create a number of packets with equal type distribution. Example n=5 cardTypes = [4, 7, 5, 11, 15] In order to make 2 matching packets, the following numbers of additional cards of each type must be added: [0, 1, 1, 1, 1]. This sums to 4 additional cards. The numbers of cards are [4, 8, 6, 12, 16] and they can be divided evenly among 2 packets. If 3 packets are created, an additional [2, 2, 1, 1, 0] cards are needed, sum = 6 items. This yields quantities [6, 9, 6, 12, 15]. Any number of packets > 2 can be created, but creating 2 packets requires the minimum number of additional cards. Function Description Complete the function cardPackets in the editor below. cardPackets has the following parameter(s): int cardTypes[n]: the quantity available of card type Returns int: the minimum number of additional cards to add Constraints • 1sns10² • 1 ≤ card Types[i] ≤ 500 Input Format For Custom Testing The first line contains an integer, n, the size of the card Types array. Each line / of the n subsequent lines (where Osi<n) contains an integer cardTypes[i].
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Introduction to computer system
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education