-
Notifications
You must be signed in to change notification settings - Fork 1
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
Oc9aN
wants to merge
2
commits into
main
Choose a base branch
from
SiHyeon
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
14 + 15주차 풀이 #55
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
|
||
for (int i = 0; i < A.size(); i++) | ||
{ | ||
answer += A[i] * B[i]; | ||
} | ||
|
||
return answer; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cpp의 신기한 메소드를 알아갑니다! 짱편해보여욥