ricardovaltierra

Airline coding challenge

Jan 14th, 2021
72
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.     // Getting the SType
  25.     while (true) {
  26.       if (lines[i][indexST].match(/[A-Z|_]+/g) === null)
  27.         break;
  28.       SType += lines[i][indexST];
  29.       indexST += 1;
  30.     }
  31.    
  32.     indexSBG = indexST;
  33.    
  34.     // Getting the SCrewId
  35.     while (true) {
  36.       if (lines[i][indexSCI].match(/[0-9]+/g) === null)
  37.         break;
  38.       SCrewId += lines[i][indexSCI];
  39.       indexSCI += 1;
  40.     }
  41.    
  42.     // Getting the SBidGroup
  43.     while (true) {
  44.       indexSBG += 1;
  45.       if (lines[i][indexSBG].match(/[0-9]+/g) === null)
  46.         break;
  47.         SBidGroup += lines[i][indexSBG];
  48.     }
  49.    
  50.     if (Object.keys(result).indexOf(SCrewId + SBidGroup) === -1){
  51.       result[SCrewId + SBidGroup] = {
  52.         "SCrewId": SCrewId,
  53.         "SBidGroup": SBidGroup,
  54.         "SType": SType
  55.       };
  56.     }
  57.     else if (STypeMatch === SType) {
  58.       result[SCrewId + SBidGroup] = {
  59.         "SCrewId": SCrewId,
  60.         "SBidGroup": SBidGroup,
  61.         "SType": SType
  62.       };
  63.     }
  64.   }
  65.  
  66.   for (const SID_SBG in result) {
  67.     console.log(`${result[SID_SBG].SCrewId} "${result[SID_SBG].SType === STypeMatch ? "YES" : "NO"}"`)
  68.   }
  69. });
RAW Paste Data