Advertisement
ricardovaltierra

Code and Test Case

Jan 15th, 2021
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. process.stdin.resume();
  2. process.stdin.setEncoding("ascii");
  3. var input = "";
  4. process.stdin.on("data", function (chunk) {
  5.     input += chunk;
  6. });
  7. process.stdin.on("end", function () {
  8.   // now we can read/parse input
  9.   const lines = input.split(/\n/);
  10.   let result = {};
  11.   const STypeMatch = "ADVANCED_TRIP";
  12.  
  13.   for (let i = 0; i < lines.length; i += 1){
  14.     let SCrewId = '';
  15.     let SType = '';
  16.     let SBidGroup = '';
  17.     let indexSCI = 0;
  18.     let indexST = 13;
  19.     let indexSBG = 0;
  20.     const myRegex = /[0-9]+\s+[A-Z|_]+\s+[A-Z|_]+\s+[0-9]+\s+[0-9]+\s+[0-9]+\s+[0-9]+\s*[A-Z|0-9|_]*/g;
  21.    
  22.    
  23.     if (lines[i].length < 1) continue;
  24.    
  25.     // Getting the SType
  26.     while (true) {
  27.       if (lines[i][indexST].match(/[A-Z|_]+/g) === null)
  28.         break;
  29.       SType += lines[i][indexST];
  30.       indexST += 1;
  31.     }
  32.    
  33.     indexSBG = indexST;
  34.    
  35.     // Getting the SCrewId
  36.     while (true) {
  37.       if (lines[i][indexSCI].match(/[0-9]+/g) === null)
  38.         break;
  39.       SCrewId += lines[i][indexSCI];
  40.       indexSCI += 1;
  41.     }
  42.    
  43.     // Getting the SBidGroup
  44.     while (true) {
  45.       indexSBG += 1;
  46.       if (lines[i][indexSBG].match(/[0-9]+/g) === null)
  47.         break;
  48.         SBidGroup += lines[i][indexSBG];
  49.     }
  50.    
  51.     if (Object.keys(result).indexOf(SCrewId + SBidGroup) === -1){
  52.       result[SCrewId + SBidGroup] = {
  53.         "SCrewId": SCrewId,
  54.         "SBidGroup": SBidGroup,
  55.         "SType": SType
  56.       };
  57.     }
  58.     else if (STypeMatch === SType) {
  59.       result[SCrewId + SBidGroup] = {
  60.         "SCrewId": SCrewId,
  61.         "SBidGroup": SBidGroup,
  62.         "SType": SType
  63.       };
  64.     }
  65.   }
  66.  
  67.   for (const SID_SBG in result) {
  68.     console.log(`${result[SID_SBG].SCrewId} "${result[SID_SBG].SType === STypeMatch ? "YES" : "NO"}"`)
  69.   }
  70. });
  71.  
  72.  
  73.  
  74.  
  75. -----------------------------------------------------------------------------------------------------------------
  76.  
  77. 101500      BIDGROUP    1   0   0   4  
  78. 101500  AWARD   UNTOUCHABLE 1   1   0   1  
  79. 101500  AWARD   TRIP_ID 1   2   0   0   7409
  80. 101500  AWARD   TRIP_ID 1   3   0   0   7906
  81. 101500  AWARD   TRIP_ID 1   4   0   0   6527
  82.  
  83. 101501      BIDGROUP    1   0   0   4  
  84. 101501  AWARD   ADVANCED_TRIP   1   1   0   1  
  85. 101501  AWARD   TRIP_ID 1   2   0   0   7409
  86. 101501  AWARD   TRIP_ID 1   3   0   0   7906
  87. 101501  AWARD   TRIP_ID 1   4   0   0   6527
  88.  
  89. 101502      BIDGROUP    1   0   0   4  
  90. 101502  AWARD   TRIP_ID 1   1   0   1  
  91. 101502  AWARD   TRIP_ID 1   2   0   0   7409
  92. 101502  AWARD   TRIP_ID 1   3   0   0   7906
  93. 101502  AWARD   TRIP_ID 1   4   0   0   6527
  94.  
  95. 232603      BIDGROUP    2   0   0   5  
  96. 232603  AWARD   UNTOUCHABLE 2   1   0   1  
  97. 232603  AVOID   LAYOVER 2   2   0   0   7409
  98. 232603  AWARD   LAYOVER 2   3   0   0   7906
  99. 232603  AWARD   LAYOVER 2   4   0   0   6527
  100. 232603  AWARD   ADVANCED_TRIP   2   5   0   0   6527
  101.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement