Guest User

Untitled

a guest
Jan 21st, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. main() {
  2. // the number of queries
  3. const n = parseInt(readLine());
  4. let count = new Array(100);
  5. count.fill(0);
  6. let values = Array.apply(null, Array(100));
  7. values = values.map(function () { return new Array(); });
  8. // calculate the histogram of key frequencies:
  9. for (let i=0; i < n; i++){
  10. let ar = readLine().split(' ');
  11. let key = parseInt(ar[0]);
  12. count[key]++;
  13. if (i < n/2) {
  14. values[key].push('-');
  15. } else
  16. {
  17. values[key].push(ar[1]);
  18. }
  19. }
  20. // calculate the starting index for each key:
  21. let output = new Array();
  22. for(let i=0; i<100; i++) {
  23. let cnt = count[i];
  24. // for the number of times the item occurs
  25. for(let j=0;j<cnt;j++){
  26. output.push(values[i].shift());
  27. }
  28. }
  29. console.log(output.join(' '));
  30. }
Add Comment
Please, Sign In to add comment