Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function calcCost(data) {
- const [
- tariffCost,
- trafficLimit,
- extraMegabyteCost,
- spentTraffic
- ] = data.toString().trim().split(/\s+/).map(Number);
- if (trafficLimit >= spentTraffic) return tariffCost;
- return tariffCost + extraMegabyteCost * (spentTraffic - trafficLimit);
- }
- var readline = require('readline');
- var rl = readline.createInterface({
- input: process.stdin,
- output: process.stdout
- });
- let result = 0;
- process.stdin.on('end', () => {
- console.log(result);
- process.exit(0);
- });
- rl.on('line', function (data) {
- result = calcCost(data);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement