Async Safe Divide
JavaScript
Easy
2 views
Problem Description
Given a and b, do a/b using async function. If b is 0, catch error and print DIV0.
Input Format
One line: a b.
Output Format
One line result or DIV0.
Constraints
a and b are integers.
Official Solution
const fs=require('fs');const p=fs.readFileSync(0,'utf8').trim().split(/\\s+/);if(!p[0])process.exit(0);const a=BigInt(p[0]),b=BigInt(p[1]);const div=async (x,y)=>{await Promise.resolve();if(y===0n)throw new Error('DIV0');return x/y;};(async()=>{try{const r=await div(a,b);process.stdout.write(r.toString());}catch(e){process.stdout.write('DIV0');}})();
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!