Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
A company manufactures different types of software products. They deliver their products to their N clients. Whenever the company fulfills the complete order of a client, the orderID generated is the concatenation of the number of products delivered for every committed product type. The head of the sales team wishes to find the clientwise data for the total number of products of any type delivered to every client.

Write an algorithm for the head of sales team to calculate the total number of products of any type delivered to the respective clients.

Input

The first line of the input consists of

an

Integer numOfClients, representing

the number of clients (N).

The second line consists of N space-

orderID,....., orderlDN-

separated Integers - orderlDo 1 representing the orderIDs of the orders delivered to the clients.


Print N space-seperated integers representing the clientwise data for the total number of products of any type delivered to each of the respective clients.

20 21

Constraints

0s numOfClients s 106

Os orderID, s 106

0s1< numOfClients

Example

Input:

4

43 345 20 987

Output:

7 12 2 24

What I have tried:

Dictionary???How do I in this Question , which datastructure will be used??
Posted
Updated 22-Jul-23 1:52am
Comments
Richard MacCutchan 22-Jul-23 3:50am    
You have tagged this question C++ and Python, but the question clearly asks you to write an algorithm. So the physical attributes of the collection of orders is not important. What is missing from the question is the actual separation of the product type from the number of orders.

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

Start by reading the assignment carefully, and working out what you need to know - then try to do it manually. Once you have it working on paper, the choice of data structures should be pretty obvious to you.
 
Share this answer
 
You can perform easily perform the task using a vector<int> (C++) or a list (Python). That is you don't need a specialized data structure (and you don't need need a specialized container either). After all you've to do is 'adding the individual digits of a integer number'.
 
Share this answer
 
Comments
Patrice T 22-Jul-23 7:37am    
+5
Quote:
How do I in this question , which datastructure will be used?

With programming, problem solving is an iterative process. You must learn how to analyze problem in order to translate to algorithms/programs.
When during analyze, you recognize a part as being a know problem, you apply the matching couple, the data structure with matching algorithm.
Recognizing a problem as a known algorithm is a matter of knowledge and experience, so a magic answer is not good for you and your learning curve.
So my advice: Learn about analyze methods, algorithms and data structures.
- Learn one or more analyze methods, E.W. Djikstra/N. Wirth Stepwize Refinement/top-Down method is a good start.
Structured Programming.pdf[^]
https://en.wikipedia.org/wiki/Top-down_and_bottom-up_design[^]
https://en.wikipedia.org/wiki/Structured_programming[^]
https://en.wikipedia.org/wiki/Edsger_W._Dijkstra[^]
https://www.cs.utexas.edu/users/EWD/ewd03xx/EWD316.PDF[^]
Program Development by Stepwise Refinement[^]
- Learn Algorithms and Data-Structures.
GitHub - The-Art-of-Computer-Programming-Books: "Everyday life is like programming, I guess. If you love something you can put beauty into it." ? Donald E. Knuth[^]
Skiena The Algorithm Design Manual
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900