Salaries grouped by department MEDIUM Structuri (BAC) 25 XP 0 solved
Mobile coding works. A laptop is faster for long sessions.

Problem

Consider the data type `Angajat`, defined as follows: ``` struct Angajat { char nume[40]; char dept[20]; int salariu; }; ``` where `nume` is the employee name, `dept` is the department code (a single word of at most 15 characters), and `salariu` is the monthly salary. Read from standard input a natural number `n`, followed by the data for `n` employees. For each distinct department, print the total sum of salaries of employees in that department. Departments are printed in the order of their first appearance in the input, one per line, in the format `dept suma`.

Input format

Input input.txt

The first line contains `n`. The next `n` lines each contain the employee name, department code, and salary, separated by spaces. - `1 <= n <= 300` - salaries are natural numbers between `1` and `100000` - the department code has between `1` and `15` characters, no spaces - the employee name has at most `30` characters, no spaces - use of `strcmp` and `strcpy` (from `<cstring>`) is permitted

Output format

Output output.txt

One line per distinct department, in the order of first appearance, containing the department code and the total salary sum, separated by a space.

Example

input
5
Maria IT 5000
Ion HR 3000
Ana IT 4500
Dan FIN 6000
Elena HR 3500
output
IT 9500
HR 6500
FIN 6000

Ready to solve this challenge?

Create a free account to write code, submit solutions, and track your progress.

⌨️ Keyboard Shortcuts

Code Editor
Run Code
Ctrl Enter
Submit Code
Ctrl Shift Enter
Format Code
Shift Alt F
Toggle Comment
Ctrl /
Undo
Ctrl Z
Redo
Ctrl Y
Navigation
Global Search
/
Show Shortcuts
?
Close Modal
Esc

🔍 Interactive Debugger

0 / 0

Analyzing your code...

📦 Variables

No variables yet

📚 Call Stack
main() line 1
📤 Output
We use cookies

Essential cookies are always active. You can choose to enable preference and analytics cookies. Learn more