memostack
article thumbnail
백준 2562번 / 최댓값 (nodejs 알고리즘 풀이)
Algorithm/Beakjoon 2022. 8. 9. 20:58

문제의 저작권은 백준 알고리즘(https://www.acmicpc.net/)에 있습니다 문제 풀이 단순히 최댓값을 구하는 문제라면, Math.max() 함수를 사용하면 좋겠지만, 몇번째 숫자인지도 구해야하기 때문에, 이터레이션을 통해 문제를 풀었다. const solution = (input) => input .map((s) => +s) .reduce( (rs, n, idx) => { if (rs[0] < n) { rs[0] = n; rs[1] = idx + 1; } return rs; }, [-Infinity, -1] ) .join('\n'); const input = []; require('readline') .createInterface({ input: process.stdin }) .on('lin..

article thumbnail
Flutter - 커스텀으로 그라디언트 버튼 만들기 (Gradient Button)
Mobile/Flutter 2022. 8. 8. 22:48

간단하게 만든다면 InkWell과 Container로 만들 수 있다. Gradient Button 쉽게 구현 코드 구현 import 'dart:developer'; import 'package:flutter/material.dart'; class GradientButton extends StatelessWidget { const GradientButton({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return InkWell( onTap: () { log("Gradient button clicked!"); }, child: Container( padding: const EdgeInsets.all(20), dec..

article thumbnail
백준 1110번 / 더하기 사이클 (nodejs 알고리즘 풀이)
Algorithm/Beakjoon 2022. 8. 7. 12:42

문제의 저작권은 백준 알고리즘(https://www.acmicpc.net/)에 있습니다 문제 풀이 두 자리수를 십의 자리와 일의 자리로 나눠서 덧셈을 하는 문제이다. 나눗셈과 나머지 연산을 이용하여, 자릿수를 잘 조작할 수 있는지 확인 하는 문제 같다. const solution = (input) => { const n = +input; if (n === 0) return 1; let cnt = 0; let nn = n; while (true) { cnt++; const a = parseInt(nn / 10); const b = nn % 10; const c = (a + b) % 10; nn = b * 10 + c; if (n === nn) break; } return cnt; }; const print..

article thumbnail
Flutter - CircleAvatar를 활용하여 Gradient Avatar 만들기 (인스타그램 아바타)
Mobile/Flutter 2022. 8. 6. 18:09

다양한 방법으로 CircleAvatar를 사용하면, 원형의 이미지를 만들 수 있다. 인스타 그램을 보면 아바타 겉에 그라데이션 border 효과가 들어가 있다. (아래 사진 참고) 구현 방법 우선 CircleAvatar를 사용하여, 원형의 아바타를 만든다. import 'package:flutter/material.dart'; class GradientBorderCircleAvatar extends StatelessWidget { const GradientBorderCircleAvatar({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return CircleAvatar( radius: 250, background..

article thumbnail
백준 10951번 / A+B - 4 (nodejs 알고리즘 풀이)
Algorithm/Beakjoon 2022. 8. 6. 15:25

문제의 저작권은 백준 알고리즘(https://www.acmicpc.net/)에 있습니다 문제 풀이 단순히 입력 받아서 두 수를 더한 값을 출력해주면 되는 간단한 문제이다. const solution = (input) => input .map((l) => { const [a, b] = l.split(' ').map((s) => +s); return a + b; }) .join('\n'); const input = []; require('readline') .createInterface({ input: process.stdin }) .on('line', (line) => input.push(line)) .on('close', (_) => { console.log(solution(input)); process..

article thumbnail
백준 10952번 / A+B - 5 (nodejs 알고리즘 풀이)
Algorithm/Beakjoon 2022. 8. 5. 20:41

문제의 저작권은 백준 알고리즘(https://www.acmicpc.net/)에 있습니다 문제 풀이 const solution = (input) => { let findZero = false; const nums = input.reduce((acc, l) => { if (findZero) return acc; if (l === '0 0') { findZero = true; } else { acc.push(l.split(' ').map((s) => +s)); } return acc; }, []); return nums .slice(0, nums.length) .map((n) => n[0] + n[1]) .join('\n'); }; const input = []; require('readline') .crea..

article thumbnail
백준 10871번 / X보다 작은 수 (nodejs 알고리즘 풀이)
Algorithm/Beakjoon 2022. 8. 4. 21:41

문제의 저작권은 백준 알고리즘(https://www.acmicpc.net/)에 있습니다 문제 풀이 첫째 줄과 두번째 줄을 입력받고 미리 정수형으로 파싱하고 문제를 풀었다. 리스트의 filter 함수를 이용하여, X보다 작은 수를 필터링했다. const solution = (input) => { const [l1, l2] = input.map((l) => l.split(' ').map((s) => +s)); return l2 .slice(0, l1[0] + 1) .filter((n) => n < l1[1]) .join(' '); }; const input = []; require('readline') .createInterface({ input: process.stdin }) .on('line', (lin..

article thumbnail
백준 2439번 / 별 찍기 - 2 (nodejs 알고리즘 풀이)
Algorithm/Beakjoon 2022. 8. 3. 21:40

문제의 저작권은 백준 알고리즘(https://www.acmicpc.net/)에 있습니다 문제 풀이 앞에 여백과 * 를 합쳐주면 되는 간단한 문제이다. repeat() 함수를 이용하면 좀 더 깔끔하게 풀 수 있다. const solution = (input) => [...Array(+input).keys()] .reduce((acc, n) => { acc.push([' '.repeat(+input - n - 1), '*'.repeat(n + 1)].join('')); return acc; }, []) .join('\n'); const print = (input) => console.log(solution(input + '')); process.stdin.on('data', print); 전체 코드 http..

article thumbnail
백준 2438번 / 별 찍기 - 1 (nodejs 알고리즘 풀이)
Algorithm/Beakjoon 2022. 8. 2. 21:11

문제의 저작권은 백준 알고리즘(https://www.acmicpc.net/)에 있습니다 문제 풀이 문자열의 repeat() 함수를 이용하면, for문을 돌리면서 문자열을 계속 더해줄 필요가 없다. const solution = (input) => [...Array(+input).keys()] .reduce((acc, n) => { acc.push('*'.repeat(n + 1)); return acc; }, []) .join('\n'); const print = (input) => console.log(solution(input + '')); process.stdin.on('data', print); 전체 코드 https://github.com/bluemiv/Algorithm/blob/master/bae..

article thumbnail
백준 11022번 / A+B - 8 (nodejs 알고리즘 풀이)
Algorithm/Beakjoon 2022. 8. 1. 20:49

문제의 저작권은 백준 알고리즘(https://www.acmicpc.net/)에 있습니다 문제 풀이 입력 받은 두 값을 더한 뒤에 Case#1: 1 + 1 = 2 형태에 맞게 출력해주면 되는 간단한 문제이다. 자주 사용하는 문법중에 문자열을 정수로 변환할때 parseInt()를 사용해도 되지만, 주로 + 기호를 이용하여 문자열을 정수로 바꿔준다. const solution = (input) => input .slice(1, input[0] + 1) .map((s, idx) => { const [a, b] = s.split(' '); return `Case #${idx + 1}: ${a} + ${b} = ${+a + +b}`; }) .join('\n'); const input = []; require('re..