Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let countFloors = Number(input[0]);
- let countRoomsForOneFloor = Number(input[1]);
- let apartment = '';
- let office = '';
- let large = '';
- for (let i = countFloors; 1 <= i; i--) {
- for (let j = 0; j < countRoomsForOneFloor; j++) {
- if (i % 2 === 0 && i !== countFloors) {
- if (j !== countRoomsForOneFloor - 1) {
- office += `О${i}${j}` + ' ';
- } else {
- office += `О${i}${j}`;
- }
- } else if (i % 2 !== 0 && i !== countFloors) {
- if (j !== countRoomsForOneFloor - 1) {
- apartment += `A${i}${j}` + ' ';
- } else {
- apartment += `A${i}${j}`;
- }
- } else {
- if (j !== countRoomsForOneFloor - 1) {
- large += `L${i}${j}` + ' ';
- } else {
- large += `L${i}${j}`;
- }
- }
- if (j === countRoomsForOneFloor - 1 && (apartment !== '' || office !== '' || large !== '')) {
- console.log(`${large}${office}${apartment}`);
- office = '';
- apartment = '';
- large = '';
- }
- } // Inner loop
- } // Outer loop
- }
Advertisement
Add Comment
Please, Sign In to add comment