Parse Integer or INVALID
JavaScript
Easy
4 views
Problem Description
One token is given. If it is a valid base-10 integer (like -12, 0, 99) print its double. Else print INVALID. Use try/catch for validation.
Input Format
One token string.
Output Format
One line output.
Constraints
Token length up to 1e5.
Official Solution
const fs=require('fs');const t=fs.readFileSync(0,'utf8').trim();if(!t)process.exit(0);try{if(!/^[+-]?\\d+$/.test(t))throw new Error('BAD');const n=BigInt(t);process.stdout.write(String(n*2n));}catch(e){process.stdout.write('INVALID');}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!