[TIL] 정글 111일차 - 나만의 무기

신승준·2022년 7월 17일
0

알고리즘

  • 프로그래머스
    • Level 1
      • 시저 암호
function solution(s, n) {
    let result = "";
    
    for (let i = 0; i < s.length; i++) {
        let temp;
        
        if (s.charCodeAt(i) === 32) {
            result += " ";
            continue;
        }
        
        if (s[i] === s[i].toLowerCase()) {
            temp = s.charCodeAt(i);
            
            if (temp + n > 122) {
                temp = 96 + (temp + n) - 122;
            } else {
                temp += n;
            }
        }
        
        if (s[i] === s[i].toUpperCase()) {
            temp = s.charCodeAt(i);
            
            if (temp + n > 90) {
                temp = 64 + (temp + n) - 90;
            } else {
                temp += n;
            }
        }
        
        result += String.fromCharCode(temp);
    }
    
    return result;
}
  • 백준
    • 정렬
      • 2628 종이 자르기
import sys
sys.stdin = open('input.txt')
input = sys.stdin.readline

width, height = map(int, input().split())
x_list = list()
y_list = list()
t = int(input())
x_list.append(0)
y_list.append(0)
x_list.append(width)
y_list.append(height)

for _ in range(t):
    axis, coordinate = map(int, input().split())
    
    if axis == 1:
        x_list.append(coordinate)
    else:
        y_list.append(coordinate)
        
x_list.sort()
y_list.sort()

max_x = 0
max_y = 0
for i in range(len(x_list) - 1):
    max_x = max(max_x, x_list[i + 1] - x_list[i])
    
for j in range(len(y_list) - 1):
    max_y = max(max_y, y_list[j + 1] - y_list[j])
    
if max_x == 0:
    max_x = width

if max_y == 0:
    max_y = height
    
print(max_x * max_y)

언어

React


궁금한 점

하루를 마치고

profile
메타몽 닮음 :) email: alohajune22@gmail.com

0개의 댓글