https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AXmwOSJaSNIDFARX 

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

char map[50][50];
int flag = 0;

void check(int y, int x) {

	int direct[4][2] = {
		0,0,
		0,1,
		1,0,
		1,1
	};

	for (int i = 0; i < 4; i++) {
		if (map[y + direct[i][0]][x + direct[i][1]] != '#') {
			flag = 1;
			return;
		}
		map[y + direct[i][0]][x + direct[i][1]] = '.';
	}
}

int main() {

	int t;
	cin >> t;
	for (int i = 0; i < t; i++) {
		int n, m;

		for (int y = 0; y < 50; y++) {
			for (int x = 0; x < 50; x++) {
				map[y][x] = '\0';
			}
		}

		cin >> n >> m;
		
		flag = 0;
		for (int y = 0; y < n; y++) {
			for (int x = 0; x < m; x++) {
				cin >> map[y][x];
			}
		}

		for (int y = 0; y < n; y++) {
			for (int x = 0; x < m; x++) {
				if (map[y][x] == '#') {
					check(y, x);
				}
				if (flag == 1) break;
			}
			if (flag == 1) break;
		}

		cout << "#" << i + 1 << " ";
		if (flag == 1) cout << "NO" << endl;
		else cout << "YES" << endl;
	}

	return 0;
}

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV7GLXqKAWYDFAXB&categoryId=AV7GLXqKAWYDFAXB&categoryType=CODE&problemTitle=2805&orderBy=FIRST_REG_DATETIME&selectCodeLang=ALL&select-1=&pageSize=10&pageIndex=1 

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

#include <iostream>
#include <vector>

using namespace std;

int map[50][50];
int n;
int sum;

void run() {
	int joo = n / 2;
	int m = 0;

	for (int i = 0; i < n; i++) {
		for (int j = joo - m; j <= joo + m; j++) {
			sum += map[i][j];
		}
		if (i < joo) m++;
		else m--;
	}
}

int main() {

	int t;
	cin >> t;
	for (int i = 0; i < t; i++) {
		cin >> n;

		sum = 0;
		for (int x = 0; x < n; x++) {
			string st;
			cin >> st;
			for (int y = 0; y < n; y++) {
				map[x][y] = st[y] - '0';
			}
		}

		run();

		cout << "#" << i + 1 << " " << sum << endl;
	}

	return 0;
}

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5LrsUaDxcDFAXc

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

#include <iostream>
#include <vector>

using namespace std;

vector<long long> arr;
int n;
int cnt = 0;
long long sum = 0;

long long run() {
	int s = arr.size();
	int tmp = arr[s - 1];

	for (int i = s-2; i >= 0; i--) {
		if (tmp <= arr[i]) {
			sum += cnt * tmp;
			cnt = 0;
			tmp = arr[i];
			continue;
		}
		sum -= arr[i];
		cnt++;
		if (i == 0) sum += cnt * tmp;
	}

	return sum;
	
}

int main() {

	int t;
	cin >> t;
	for (int i = 0; i < t; i++) {

		cin >> n;

		arr.clear();
		for (int x = 0; x < n; x++) {
			int num;
			cin >> num;
			arr.push_back(num);
		}

		sum = 0;
		cnt = 0;
		long long result = run();

		cout << "#" << i + 1 << " " << result << endl;
	}

	return 0;
}

- CLI실행 : 터미널 실행 단축키 -> Ctrl + Alt + T

- 새 탭 열기 : Ctrl + Shift + T

- 탭 닫기 : Ctrl + Shift + W

- Ctrl + S : 일시정지(stop, 저장x) 

- Ctrl + Q : 재생(start)

 

- pwd : print working directory

 

- touch [파일명] : 새로운 빈 파일 생성 (있는 파일이라면, 변경된 현재 시간으로 업데이트)

- rm [파일명]

 ->rm -r(하위폴더까지 삭제)/ rm -rf(물어보지않고 완전삭제)

 

- vi사용법

 -> 단어 찾기 :  /찾을단어 (n다음 N이전)

 -> 단어 바꾸기 : %s /찾을단어 /바꿀단어 /g

 -> G(맨 아랫줄), gg(맨 윗줄), $(문장 맨 끝)

 -> u(Undo실행취소), Ctrl + r(Redo다시실행)


- 현재 사용자명 출력 -> users

- 현재 host명 출력 -> hostname

- 부팅 후 시간 출력 -> uptime -p

- 로그인 가능한 user 목록들 출력하기
 -> cat /etc/passwd | grep bash

- 심볼릭링크 usr/bin/ 내부에 생성하기
 -> sudo ln -s /home/nakyung/w/now(절대경로) /usr/bin

- 사용자 바꾸기 
(root권한)
 -> sudo su (루트로 사용자 전환하기 -> exit)
 -> su root 불가,루트의 비밀번호는 host도 알지 못하기때문(보안을 위해 root의 비밀번호는 지정하지 않음) :  sudo 명령어를 사용할 수 있는 "sudoer = nakyung"를 사용하여 root권한 명령어 사용가능
 -> sudo vi /etc/sudoers(sudoer 추가가능 wq!)

(일반사용자) 
-> su tigerstar (전 사용자 로그아웃하지 않고, 사용자 전환 -> exit)

apt 설치하기
-> sudo apt install app이름
-> app list --installed 옵션 : 설치 된 패키지 확인

-> apt show [패키지이름] : 패키지 정보 확인

(apt는 설치에 필요한 의존 패키지들 자동 설치)

apt 삭제하기
 -> sudo apt purge app이름

사용자 추가/삭제
 -> sudo adduser [계정명]
(useradd도 사용은 가능하나 홈디렉토리 등 세부설정 따로 해줘야 됨)
 -> sudo deluser --remove-home [계정명]
 (deluser [계정명] : 홈디렉토리는 삭제안됨)

그룹 추가/삭제
 -> sudo addgroup [그룹명]
 -> sudo gpasswd -a [추가할계정] [그룹에]
 -> sudo delgroup [그룹명]
 -> sudo gpasswd -d [삭제할계정] [그룹에서]

 

파일 소유권

chown [소유user]:[소유group] [파일명]

ex) work디렉토리 내부 파일 모두 한꺼번에 권한 설정 : sudo chown -R onnew:embedded ~/work

 

파일 권한 이해 user/group/other

sudo chmod 404 ./aaa

 

 

로그인가능한 사용자 확인

cat /etc/passwd | grep bash

cat /etc/group

 

find와 which

- find [경로] -name [찾는이름] -type f/d

- which [찾는이름]

 

심볼릭 링크

ln -s [/usr/bin/ls] bts -> ls -al ./bts 

프로젝트 생성

vue create [프로젝트명]

Manually select feautres

-> linter space로 해제<

-> router, vuex 설정

그후 나머지 default로 전부다 enter

 

cd 프로젝트폴더

run serve -> Local 주소에서 확인

 

부모component -> 자식component : props

자식component -> 부모component  : emit

 

라우팅 -> 이동시키는것/ 매핑

클라이언트 사이드 랜더링 VS 서버 사이드 렌더링
장) 페이지 전환이 빠르다  장)다운 받을 정보가 적다
단) 초기랜더링에 시간이 걸린다  단) 초기랜더링에 시간이 덜 걸린다.
한번 로딩(다운롣 되면) 페이지 라우팅이 빠르다

 

뷰 부트스트랩

- 설치명령어

  npm install axios bootstrap bootstrap-vue

- main.js에 복붙(사이트에 있음)

import { BootstrapVue, IconsPlugin } from 'bootstrap-vue'

// Import Bootstrap an BootstrapVue CSS files (order is important)
import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap-vue/dist/bootstrap-vue.css'



// Make BootstrapVue available throughout your project
Vue.use(BootstrapVue)
// Optionally install the BootstrapVue icon components plugin
Vue.use(IconsPlugin)
Vue.config.productionTip = false

 

Front-end 개발 방향

angular (프레임워크) - 양방향 바인딩
react (라이브러리) - 가상돔
vue (프레임워크) - 양방향 바인딩 + 가상 돔
svelte
프레임워크 - 붕어빵 틀 (주권이 프레임워크)
 : 전체는 정해져있고, 일부를 개발자가 변경 

라이브러리(주권이 개발자)
 : 책을 대여해서, 과제를 해결하고 반납 
-> 제어권의 역전

자바스크립트에서의 this : "함수 호출 시점"에 바인딩(정해진다)

1. 일반함수로 호출 -> 전역객체

2. 메서드로 호출 -> 그 메서드를 소유한 객체

bbq() -> window.msg, window.nextMsg

app.bbq() -> app.msg, app.nextMsg

 

재설치를 위한 vue-cli 삭제

npm uninstall vue-cli-g

 

vue 설치

npm i -g @vue/cli

npm i vue-cli -global

npm i @vue/cli

npm i vue-cli -g

 

설치 확인

vue --version

 

버전3 재설치하기

npm uninstall -g vue-cli
npm install -g @vue/cli

 

정책 변경

Set-ExecutionPolicy RemoteSigned

 

프로젝트 생성

vue create [프로젝트명]

Manually select feautres

-> linter space로 해제<

그후 나머지 default로 전부다 enter

- 첫번째 문자열과 두번째 문자열의 가장 긴 중복구간 찾기(출제율 높음)

#include<iostream>
#include<string>
#include<unordered_map>
using namespace std;
int main()
{
    string a = "ATSBBTYG";
    string b = "GTSBB";

    int len1 = a.length();
    int len2 = b.length();

    unordered_map<string, int>m;


    for (int t = len2; t > 0; t--)  // b의 길이만큼 확인
    {

        // a를 잘라서 등록
        for (int x = 0; x <= len1 - t; x++)  
        {
            string temp = a.substr(x, t); //  0인덱스부터  5개   1 5개..   3 5개
            m[temp] = t;                //  0 4개  1 4개 2 4개 3 4개 4 4개
        }
        // b를 잘라서 확인
        for (int x = 0; x <= len2 - t; x++)
        {
            string temp = b.substr(x, t);     //5개 
            if (m.count(temp) == 1) {        // 0 4개  1 4개
                cout << m[temp];
                return 0;
            }

        }
    }


    return 0;
}

- 각 배열에서 선택한 숫자의 합(어려움)

#include<iostream>
#include<unordered_map>
using namespace std;
unordered_map<int, int > m;
int a[6] = {4,-1,8,3,5,2};
int b[6] = {-4,1,-3,-5,6,1};
int c[6] = {2,7,1,2,9,5};
int d[6] = {4,-3,2,1,7,6};
int main()
{
    for (int y = 0; y < 6; y++)
    {
        for (int x = 0; x < 6; x++)
        {
            int sum = a[x] + b[y];
            m[sum] += 1;
        }
    }
    int result = 0;
    for (int y = 0; y < 6; y++)
    {
        for (int x = 0; x < 6; x++)
        {
            int sum = -(c[y] + d[x]);
            result += m[sum];
        }
    }

    cout << result;


    return 0;
}

- 2차원 배열에서 target 찾기

#include<iostream>
#include<string>
#include<unordered_map>
using namespace std;

string arr[7] = {
    "asdfasd",
    "asdfasd",
    "asdfasd",
    "asdfAAd",
    "asdfAAd",
    "asdfAAd",
    "asdfasd",
};

string target[3] = {
    "AA",
    "AA",
    "AA",
};  
struct axis {
    int y, x;
};
unordered_map<string, axis>a;
// arr 배열에 target이 있는지 없는지 존재 여부 출력 !!

string getkey(int dy, int dx)
{
    string temp;
    for (int y = 0; y < 3; y++) {
        for (int x = 0; x < 2; x++)
        {
            temp += arr[dy + y][dx + x];
        }
    }
    return temp;
}

string getkey2()
{
    string temp;
    for (int y = 0; y < 3; y++)
    {
        for (int x = 0; x < 2; x++)
        {
            temp += target[y][x];
        }
    }
    return temp;
}

void sett()
{
    for (int y = 0; y < 7 - 3; y++)
    {
        for (int x = 0; x < 7 - 2; x++)
        {
            string key = getkey(y, x);
            a[key] = { y,x };
        }
    }
}
int main() {
    sett();

    string key = getkey2();
    if (a.count(key) == 1)cout << "존재";

}

- 입력받은 문자열의 위치 출력하기

#include<iostream>
#include<string>
#include<unordered_map>
using namespace std;
struct axis {
    int y, x;
};
string arr[3][3] = {
    "r","iu","apa",
    "nct","bp","snsd",
    "yc","bts","am"
};

unordered_map<string, axis>a;
void sett() {
    for (int y = 0; y < 3; y++)
    {
        for (int x = 0; x < 3; x++)
        {
            a[arr[y][x]] = { y,x };
        }
    }

}
int main()
{
    sett();
    string input;
    cin >> input;

    cout << a[input].y << " " << a[input].x;


    return 0;
}

- 문자열

#include<iostream>
#include<unordered_map>
#include<vector>
using namespace std;
unordered_map<string, int>h;

int main()
{
    h["bob"] = 44;
    h["kate"] = 14;
    h["kevin"] = 54;
    h["jane"] = 24;
    h["mark"] = 94;

    string input;
    cin >> input;

    //if (h[input] == 1)cout << "찾음";
    if (h.count(input) == 1)cout << "찾음";
    else cout << "없음";

    //for (auto x = h.begin(); x != h.end(); x++)
    //{
    //    cout << x->first << " " << x->second << endl;
    //}


    //vector<int>vect = { 1,2,3,4,5 };
    //for (auto x = vect.begin(); x != vect.end(); ++x)
    //{
    //    cout << *x;
    //}


    return 0;
}

- STL 사용하기

#include <iostream>
#include <unordered_map>

using namespace std;

unordered_map<int, int>k;

int main() {
	int vect[5] = { 1,2,3,100,7 };
	for (int x = 0; x < 5; x++) {
		k[vect[x]] = 1;
	}

	int n;
	cin >> n;

	if (k[n] == 1) cout << "존재";
	else cout << "없음";

	return 0;
}

- addnode

#include<iostream>
using namespace std;
struct node {
    int a;
    node* next;
};

node* head, * last;
void addnode(int x)
{
    if (head == NULL)
    {
        head = new node();
        head->a = x;
        last = head;
    }
    else {
        last->next = new node();
        last = last->next;
        last->a = x;
    }

}
int main()

{

    for (int x = 1; x < 100; x++)
    {
        addnode(x);
    }



    return 0;
}

- Linked List 사용하기

#include<iostream>
#include<ctime>
using namespace std;
int vect[5] = { 3,2,100,1,4 };

struct node {
    int x;
    node* next;
};
node* head[3], * last[3];
void addnode(int from,int a)
{
    if (head[from] == NULL) {
        head[from] = new node();
        head[from]->x = a;
        last[from] = head[from];
    }
    else
    {
        last[from]->next = new node();
        last[from] = last[from]->next;
        last[from]->x = a;
    }
}

int hashf(int key)
{
    return key % 3;
}


void dat()
{
    for (int x = 0; x < 5; x++)
    {
        int hcode = hashf(vect[x]);
        addnode(hcode, vect[x]);

    }
}
int main()
{
    time_t start = clock();
    dat();
    int n;
    cin >> n;

    int hashcode = hashf(n);
    for (node* p = head[hashcode]; p != NULL; p = p->next)
    {
        if (p->x == n) {
            cout << "발견";
            return 0;
        }
    }
    cout << "미발견";

    cout << (int)(clock() - start) << "ms";

    return 0;
}

 

- 강사님 코드

 ->  2중for문 이용하여 swap후 돌아올때 원상복구하기

#include <iostream>
#include <cstring>
using namespace std;

char str[100];
int n;

int maxi;
int limit;

int calc() {
	int sum = 0;
	for (int i = 1; i < n; i++) {
		char ca = str[i - 1];
		char cb = str[i];

		if (ca == cb) sum -= 50;
		if (abs(ca - cb) <= 5) sum += 3;
		if (abs(ca - cb) >= 20) sum += 10;
	}

	return sum;
}

void run(int level) {
	if (level == limit) {
		int ret = calc();		
		if (maxi <= ret) maxi = ret;
		return;
	}

	for (int a = 0; a < n - 1; a++) {
		for (int b = a + 1; b < n; b++) {
			swap(str[a], str[b]);
			run(level + 1);
			swap(str[a], str[b]);
		}
	}
}

int main()
{
	cin >> str;
	cin >> limit;

	n = strlen(str);
	run(0);
	cout << maxi;

	return 0;
}

- 제출코드

#include <iostream>
#include <queue>
#include <cstring>

using namespace std;

char input[10];
char cinput[10];

int path[10];
int n;

vector<pair<int, int>>tmp;

int Max = 0;

void run(int le, int st) {
	if (le == 2) {
		tmp.push_back(make_pair(path[0], path[1]));
		return;
	}

	for (int i = st; i < strlen(input); i++) {
		path[le] = i;
		run(le + 1, i + 1);
		path[le] = 0;
	}

}

void change(int a, int b) {
	char tmp = cinput[a];
	cinput[a] = cinput[b];
	cinput[b] = tmp;
}

pair<int,int> ret[10];
void run2(int le) {
	if (le == n) {
		for (int i = 0; i < strlen(input); i++) {
			cinput[i] = input[i];
		}

		for (int i = 0; i < n; i++)
			change(ret[i].first, ret[i].second);

		int sum = 0;
		for (int x = 1; x < strlen(input); x++) {
			int num = cinput[x] - cinput[x - 1];
			if (num == 0) sum -= 50;
			else if (abs(num) <= 5) sum += 3;
			else if (abs(num) >= 20) sum += 10;
		}

		//cout << cinput << " ";
		//cout << sum << endl;
		if (sum > Max)Max = sum;

		return;
	}

	for (int i = 0; i < tmp.size(); i++) {
		ret[le] = tmp[i];
		run2(le + 1);
	}
}

int main()
{
	cin >> input >> n;

	run(0,0);

	run2(0);
	
	cout << Max;

	return 0;
}

+ Recent posts