Void-voiD

Untitled

Dec 21st, 2018
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. #! /usr/bin/env node
  2. 'use-strict'
  3.  
  4. const process = require('process');
  5. const fs = require('fs');
  6.  
  7. try {
  8. const dict = fs.readFileSync(process.argv[2], 'utf8');
  9. const expr = fs.readFileSync(process.argv[3], 'utf8');
  10. const dic = [];
  11. let j = 0;
  12. let i;
  13. let cur = '';
  14. for (i = 0; i < dict.length; i++) {
  15. if (cur.length !== 0 && (dict[i] === ',' || dict[i] === '.' || dict[i] === ' ' || dict[i] === '\n')) {
  16. dic[j] = cur;
  17. j++;
  18. cur = '';
  19. }
  20. else {
  21. if (dict[i] !== ',' && dict[i] !== '.' && dict[i] !== ' ' && dict[i] !== '\n') cur += dict[i];
  22. }
  23. }
  24. cur = '';
  25. let x = 1;
  26. let y = 1;
  27. let is = 0;
  28. for (i = 0; i < expr.length; i++) {
  29. if (cur.length !== 0 && (expr[i] === ',' || expr[i] === '.' || expr[i] === ' ' || expr[i] === '\n')) {
  30. for (j = 0; j < dic.length; j++) {
  31. if (0 === cur.localeCompare(dic[j])) {
  32. is = 1;
  33. break;
  34. }
  35. }
  36. if (is === 0) {
  37. console.log(x + ',' + ' ' + (y - cur.length) + ' ' + cur);
  38. }
  39. if (expr[i] === ',' || expr[i] === '.' || expr[i] === ' ') y++;
  40. if (expr[i] === '\n') {
  41. x++;
  42. y = 1;
  43. }
  44. cur = '';
  45. is = 0;
  46. }
  47. else {
  48. if (expr[i] !== ',' && expr[i] !== '.' && expr[i] !== ' ' && expr[i] !== '\n') {
  49. cur += expr[i];
  50. y++;
  51. }
  52. if (expr[i] === ',' || expr[i] === '.' || expr[i] === ' ') y++;
  53. if (expr[i] === '\n') {
  54. x++;
  55. y = 1;
  56. }
  57. }
  58. }
  59. } catch (e) {
  60. console.error(e.message);
  61. }
Add Comment
Please, Sign In to add comment