Skip to content

14 + 15주차 풀이 #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions SiHyeon/week14/2016년.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <string>
#include <vector>

using namespace std;

string solution(int a, int b)
{
int month[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; // 1~12월 날 수
string day[] = {"FRI", "SAT", "SUN", "MON", "TUE", "WED", "THU"}; // 금요일부터 시작
int index = 0; // 월의 날 수를 다 더한 값
for (int i = 0; i < a - 1; i++)
index += month[i];
index = (index + b) % 7 - 1;
return day[index == -1 ? 6 : index];
}
25 changes: 25 additions & 0 deletions SiHyeon/week14/시저 암호.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <string>
#include <vector>

using namespace std;

string solution(string s, int n)
{
string answer = "";
// s하나씩 n만큼 이동 후 answer에 저장
// n이 동시 z Z를 넘어서는 경우 대문자 소문자 구분해서 처리
for (auto c : s)
{
if (isalpha(c))
{
if (c + n > 'z' && islower(c)) // 소문자 z를 넘어가는 경우
c = ('a' - 1) + (c + n - 'z');
else if (c + n > 'Z' && isupper(c)) // 대문자 Z를 넘어가는 경우
c = ('A' - 1) + (c + n - 'Z');
else // 안넘어가는 경우
c = c + n;
}
answer += c;
}
return answer;
}
19 changes: 19 additions & 0 deletions SiHyeon/week14/최솟값 만들기.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int solution(vector<int> A, vector<int> B)
{
int answer = 0;

sort(A.begin(), A.end());
sort(B.rbegin(), B.rend());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cpp의 신기한 메소드를 알아갑니다! 짱편해보여욥


for (int i = 0; i < A.size(); i++)
{
answer += A[i] * B[i];
}

return answer;
}
30 changes: 30 additions & 0 deletions SiHyeon/week15/롤케이크 자르기.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <string>
#include <vector>
#include <set>
#include <map>

using namespace std;

int solution(vector<int> topping)
{
int answer = 0;
// map에 토핑 종류와 갯수를 저장
// topping의 순서대로 map에서 갯수를 빼줌
// 빼준 종류의 수와 map에서 0이 아닌 종류의 수가 같으면 같은 분배
// 빼준 종류의 수는 set으로 계산
map<int, int> rollCake;
for (auto t : topping)
rollCake[t]++;
set<int> takeSet;
for (int i = 0; i < topping.size(); i++)
{
takeSet.insert(topping[i]); // 철수가 가져가고
rollCake[topping[i]]--; // 토핑 갯수 감소
if (rollCake[topping[i]] == 0)
rollCake.erase(rollCake.find(topping[i]));

if (rollCake.size() == takeSet.size())
answer++;
}
return answer;
}
71 changes: 71 additions & 0 deletions SiHyeon/week15/방금그곡.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include <string>
#include <vector>
#include <sstream>

using namespace std;

vector<string> split(string input, char delimiter)
{
vector<string> answer;
stringstream ss(input);
string temp;

while (getline(ss, temp, delimiter))
{
answer.push_back(temp);
}

return answer;
}

string traslateString(string str)
{
const vector<string> exception = {"C#", "D#", "F#", "G#", "A#"};
for (int i = 0; i < exception.size();)
{
int index = str.find(exception[i]);
if (index == string::npos)
i++; // 없으면 다음 문자 탐색
else
{
// 있으면 치환
str.replace(index, 2, to_string(i));
}
}
return str;
}

string solution(string m, vector<string> musicinfos)
{
// 반복재생된 횟수를 구한다
// 횟수를 기반으로 반복된 멜로디를 구한다
// 반복된 멜로디에 m이 있는지 확인한다
// #을 처리하기위해 #이 붙은 문자를 다른 문자로 바꿔준다
// C# -> 0, D# -> 1, F# -> 2, G# -> 3, A# -> 4 로 치환해서 계산
string name = "(None)";
int time = 0;
for (auto info : musicinfos)
{
vector<string> song = split(info, ',');
// 재생시간 구하기
int timeDiff = stoi(song[1].substr(0, 2)) - stoi(song[0].substr(0, 2));
int minDiff = stoi(song[1].substr(3, 2)) - stoi(song[0].substr(3, 2)) + 1;
int playTime = ((timeDiff * 60) + minDiff);

song[3] = traslateString(song[3]);
m = traslateString(m);

string melody = ""; // 재생된 멜로디
for (int i = 0; i < playTime; i++)
melody.push_back(song[3][i % song[3].length()]);

printf("%s", melody.c_str());

if (melody.find(m) != string::npos && time < playTime)
{
name = song[2];
time = playTime;
}
}
return name;
}
22 changes: 22 additions & 0 deletions SiHyeon/week15/정수 삼각형.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <string>
#include <vector>

using namespace std;

int solution(vector<vector<int>> triangle)
{
int answer = 0;
// 밑에서부터 위에 더했을때 큰 값을 더해줌
for (int i = triangle.size() - 1; i > 0; i--)
{
for (int j = 0; j < triangle[i].size() - 1; j++)
{
if (triangle[i][j] > triangle[i][j + 1])
triangle[i - 1][j] += triangle[i][j];
else
triangle[i - 1][j] += triangle[i][j + 1];
}
}
answer = triangle[0][0];
return answer;
}