How to resolve the algorithm Top rank per group step by step in the HicEst programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Top rank per group step by step in the HicEst programming language

Table of Contents

Problem Statement

Find the top   N   salaries in each department,   where   N   is provided as a parameter. Use this data as a formatted internal data structure (adapt it to your language-native idioms, rather than parse at runtime), or identify your external data source:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Top rank per group step by step in the HicEst programming language

Source code in the hicest programming language

CHARACTER source="Test.txt", outP='Top_rank.txt', fmt='A20,A8,i6,2x,A10'
CHARACTER name*20, employee_ID*10, department*10, temp*10
REAL ::   idx(1), N_top_salaries=3

! Open the source with 4 "," separated columns, skip line 1:
OPEN(FIle=source, Format='SL=1;4,;', LENgth=L)
ALLOCATE(idx, L)

! Sort salary column 3 descending, then department column 4, store in idx:
SORT(FIle=source, Column=3, Descending=1, Column=4, Index=idx)

! Display a spreadsheet-like scrolling dialog of the presorted source:
DLG(Text=idx, Text=source, Format=fmt, Y)

! Output the first N top salaries of each department_
OPEN(FIle=outP)
DO i = 1, L
   rank = rank + 1
   READ(FIle=source, Row=idx(i)) name, employee_ID, salary, department
   IF(temp /= department) THEN
       rank = 1
       WRITE(FIle=outP)
       temp = department
   ENDIF
   IF(rank <= N_top_salaries) THEN
       WRITE(FIle=outP, Format=fmt) name, employee_ID, salary, department
   ENDIF
ENDDO

END

  

You may also check:How to resolve the algorithm GUI/Maximum window dimensions step by step in the Icon and Unicon programming language
You may also check:How to resolve the algorithm Julia set step by step in the COBOL programming language
You may also check:How to resolve the algorithm Animation step by step in the J programming language
You may also check:How to resolve the algorithm Parametric polymorphism step by step in the Ada programming language
You may also check:How to resolve the algorithm SHA-1 step by step in the Haxe programming language