Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions problems/week01/SWEA_1209/CryingDitto/1209.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// 1209.[S / W 문제해결 기본] 2일차 - Sum
// https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV13_BWKACUCFAYh
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);

for (int tc = 0; tc < 10; tc++)
{
int tNum;
cin >> tNum;
int mat[100][100] = { 0 };
int colMax = 0, rowMax = 0, rightToLeft = 0, leftToRight = 0;

for (int i = 0; i < 100; i++)
{
int curCol = 0, curRow = 0;

for (int j = 0; j < 100; j++)
{
int num;
cin >> num;
// row 누적합
curRow += num;

// col 누적합
if (i > 0)
{
mat[i][j] = mat[i - 1][j] + num;
}
else
{
mat[i][j] = num;
}

// 대각선 합
if (i == j)
{
leftToRight += num;
}
if (i + j == 99)
{
rightToLeft += num;
}

// col 최댓값 계산
if (i == 99)
{
colMax = mat[i][j] > colMax ? mat[i][j] : colMax;
}
}
rowMax = curRow > rowMax ? curRow : rowMax;
}

int ans = max({rowMax, colMax, leftToRight, rightToLeft})
/*if (ans < rowMax)
{
ans = rowMax;
}
if (ans < colMax)
{
ans = colMax;
}
if (ans < leftToRight)
{
ans = leftToRight;
}
if (ans < rightToLeft)
{
ans = rightToLeft;
}*/
cout << "#" << tNum << " " << ans << "\n";
}
return 0;
}
76 changes: 76 additions & 0 deletions problems/week01/SWEA_1244/CryingDitto/1244.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// 1244. [S/W 문제해결 응용] 2일차 - 최대 상금
// https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV15Khn6AN0CFAYD
// 2자리 골라서 바꾸는 모든 경우의 수 탐색해야 할 것 같다는 느낌은 들었는데 풀지는 못했음
// 바꾸고 나서 방문 배열을 어떻게 작성할지 몰랐던 것 같음
// AI 도움 받아서 풀이 과정 이해하고 혼자서 다시 적어보았음
// 근데 다시 풀라고 하면 풀 수 있을지...? ㅎㅎ...

#include <iostream>
#include <vector>
#include <string>
#include <algorithm> // swap
#include <cstring> // memset

#define MAX 1000000
using namespace std;

int swapCnt;
string str;
// 교환 횟수 10회, 숫자 6자리므로 범위 최대 999999
bool visited[11][1000000];
int maxResult = 0;
// algorithm의 swap 함수 사용

void dfs(int curSwapCnt)
{
if (curSwapCnt == swapCnt)
{
maxResult = max(maxResult, stoi(str));
return;
}

int sNum = stoi(str);

// 같은 횟수 교환했을 때 이미 확인한 결과라면 리턴
if (visited[curSwapCnt][sNum]) return;

visited[curSwapCnt][sNum] = true;

int size = str.length();
// 가능한 6자리 중 두 자리 뽑아서 바꾸는 과정
// i=0, j=1일 때와 j=1, i=0일 때는 같은 경우이므로 범위를 아래처럼 적음
for (int i = 0; i < size - 1; i++)
{
for (int j = i + 1; j < size; j++)
{
swap(str[i], str[j]);
dfs(curSwapCnt + 1);
swap(str[i], str[j]);
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);

int T;
cin >> T;

for (int tc = 0; tc < T; tc++)
{
// 숫자문자열, 교환 횟수
cin >> str >> swapCnt;
maxResult = 0;
memset(visited, false, sizeof(visited));

// memset 안 쓰면
/*for (int i = 0; i < 11; i++)
{
fill(visited[i], visited[i] + MAX, false);
}*/
dfs(0);
cout << "#" << tc + 1 << " " << maxResult << "\n";
}
return 0;
}
69 changes: 69 additions & 0 deletions problems/week01/SWEA_1954/CryingDitto/1954.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// 1954.달팽이 숫자
// https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5PobmqAPoDFAUq
#include <iostream>
#include <vector>
using namespace std;

int main()
{
ios::sync_with_stdio(false);
cin.tie(0);

int T;
cin >> T;
for (int tc = 0; tc < T; tc++)
{
int size;
cin >> size;
vector<vector<int>> snail(size, vector<int>(size, 0));
vector<vector<bool>> visited(size, vector<bool>(size, false));

// 방향: 우 -> 하 -> 좌 -> 상
int dIndex = 0;
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = { 1, 0, -1, 0 };
// 집어넣을 숫자
int num = 1;
// 배열 index
int x = 0; int y = 0;
int nx = 0; int ny = 0;

// 근데 i, j를 안 쓰고 N도 작아서 굳이 이중for문 쓸 거 없이 그냥 size*size loop 돌려도 될 거 같네요.
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++) {
snail[x][y] = num;
visited[x][y] = true;

nx = x + dx[dIndex];
ny = y + dy[dIndex];

// 가능한 index 범위 벗어난 경우
if (nx < 0 || nx >= size || ny < 0 || ny >= size)
{
// 방향 전환
dIndex = (dIndex + 1) % 4;
}
else if (visited[nx][ny]) {
// index 범위에 해당하지만 이미 visit한 경우 방향 꺾어야 함
dIndex = (dIndex + 1) % 4;
}
x = x + dx[dIndex];
y = y + dy[dIndex];
num++;
}
}

// 정답 배열 출력
cout << "#" << tc + 1 << "\n";
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++) {
cout << snail[i][j] << " ";
}
cout << "\n";
}
}

return 0;
}
51 changes: 51 additions & 0 deletions problems/week01/SWEA_2001/CryingDitto/2001.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// 2001. 파리 퇴치
// https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5PzOCKAigDFAUq
#include <iostream>
#include <vector>
using namespace std;

int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);

int T;
cin >> T;
for (int tc = 0; tc < T; tc++)
{
int size, rangeSize;
cin >> size >> rangeSize;

vector<vector<int>> mat(size, vector<int>(size, 0));

for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
{
cin >> mat[i][j];
}
}
int maxSum = 0;
for (int i = 0; i < size - rangeSize + 1; i++)
{
for (int j = 0; j < size - rangeSize + 1; j++)
{
int curSum = 0;

for (int kx = 0; kx < rangeSize; kx++)
{
for (int ky = 0; ky < rangeSize; ky++)
{
int nx = i + kx;
int ny = j + ky;
curSum += mat[nx][ny];
}
}
maxSum = curSum > maxSum ? curSum : maxSum;
}
}

cout << "#" << tc + 1 << " " << maxSum << "\n";
}
return 0;
}
Loading