Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Game
- // Three friends came up with a game for having fun in the break between the classes.
- // One of them says a three-digit number and the others use it to form a mathematical expressions
- // by using operators for sum and multiplication between the digits of that number.
- // The winner is the first one who founds the biggest number that is a result of the above mentioned rules.
- // Write a program 'game', which prints out that biggest number.
- // Input
- // Read from the standard input
- // The first line of the input will be positive three-digit number N.
- // Output
- // Print on the standard output
- // The result should be the calculated biggest number.
- // Sample tests
- // Input
- // 185
- // Output
- // 41
- // Input
- // 111
- // Output
- // 3
- const input = ['345'];
- const print = this.print || console.log;
- const gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
- const initialNum = gets();
- const hundreds = Number(initialNum[0]);
- const tenths = Number(initialNum[1]);
- const units = Number(initialNum[2]);
- const maxNum = Math.max((hundreds * tenths * units), (hundreds * tenths + units), (hundreds + tenths * units), (hundreds + tenths + units));
- print(maxNum);
Advertisement
Add Comment
Please, Sign In to add comment