10 Oct 2020 |
PS
HHKB Programming Contest 2020 B번 Futon
문제
https://atcoder.jp/contests/hhkb2020/tasks/hhkb2020_b

풀이
매트리스를 총 몇가지 방법으로 설치할 수 있는지 묻는 문제
모든 점에 대하여 연속으로 2칸이 존재하는 경우가 총 몇 가지 인지 카운트 한뒤
마지막에 중복을 제거하기 위해 반으로 나누었다.
코드
#pragma warning(disable : 4996)
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef tuple<ll,ll,ll> tl3;
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a))
#define rep(i, n) FOR(i, 0, n)
#define repn(i, n) FORN(i, 1, n)
#define tc(t) while (t--)
// https://atcoder.jp/contests/hhkb2020/tasks/hhkb2020_b
ll h,w;
ll dir[4][2];
bool isAvailable(ll x, ll y){
if(x >= 0 && y >= 0 && x < h && y < w) return true;
else return false;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
dir[0][0] = dir[1][0] = dir[2][1] = dir[3][1] = 0;
dir[0][1] = dir[2][0] = 1;
dir[1][1] = dir[3][0] = -1
cin >> h >> w;
vector<string> v(h);
rep(i,h){
cin >> v[i];
}
ll ans = 0;
rep(i,h){
rep(j,w){
if(v[i][j] == '.'){
rep(k,4){
ll x = i+dir[k][0];
ll y = j+dir[k][1];
if(isAvailable(x,y) && v[x][y] == '.') ans++;
}
}
}
}
cout << ans/2;
return 0;
}
10 Oct 2020 |
PS
HHKB Programming Contest 2020 A번 Keyboard
문제
https://atcoder.jp/contests/hhkb2020/tasks/hhkb2020_a

풀이
S에 ‘Y’가 입력되면 T를 대문자로
S에 ‘N’이 입력되면 T를 소문자로 출력
코드
#pragma warning(disable : 4996)
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef tuple<ll,ll,ll> tl3;
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a))
#define rep(i, n) FOR(i, 0, n)
#define repn(i, n) FORN(i, 1, n)
#define tc(t) while (t--)
// https://atcoder.jp/contests/hhkb2020/tasks/hhkb2020_a
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
string s,t;
cin >> s >> t;
if(s[0] == 'Y') {
cout << (char)(t[0]-32);
}
else{
cout << t;
}
return 0;
}
09 Oct 2020 |
PS
백준 1550번 16진수
문제
https://www.acmicpc.net/problem/1550

풀이
단순한 출력형식 변경으로 해결 가능한 문제
코드
#pragma warning(disable : 4996)
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef tuple<ll,ll,ll> tl3;
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a))
#define rep(i, n) FOR(i, 0, n)
#define repn(i, n) FORN(i, 1, n)
#define tc(t) while (t--)
// https://www.acmicpc.net/problem/1550
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n;
cin >> uppercase >> hex >> n;
cout << n;
return 0;
}
08 Oct 2020 |
Backend
Nestjs 튜토리얼 따라하기 1편
https://docs.nestjs.com/
Nestjs는 Node.js의 server-side를 구축하기 위한 프레임워크이다.
설치
Node.js (≥ 10.13.0) 를 필요로 한다.
시작을 위해 Nest CLI를 설치한다.
$ npm i -g @nestjs/cli
$ nest new project-name
위 명령어를 이용하여 프로젝트를 생성하면 다음과 같은 구조를 가진다.
├── src
│ ├── app.controller.ts
│ ├── app.module.ts
│ └── main.ts
File |
Description |
app.controller.ts |
단일 Route를 가진 샘플 컨트롤러 |
app.module.ts |
어플리케이션의 Root 모듈 |
main.ts |
NestFactory를 사용하여 Nest 어플리케이션 인스턴스를 생성 |
main.ts는 async 함수를 포함하고 있으며 Nest 어플리케이션 인스턴스를 생성한다.
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
await app.listen(3000);
}
bootstrap();
Nest 어플리케이션 인스턴스를 생성하기 위해서 NestFactory 클래스를 사용한다.
NestFactory의 create() 메소드를 사용하게 되면 INestApplication 인터페이스로 구성된 어플리케이션 객체를 반환한다.
실행
어플리케이션을 시작한뒤 http://localhost:3000/ 를 실행하면 Hello World! 메시지를 볼 수 있다.