-
Notifications
You must be signed in to change notification settings - Fork 0
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
[그리디] 10월 23일 #10
Open
hak2711
wants to merge
1
commit into
main
Choose a base branch
from
1004-greedy
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
[그리디] 10월 23일 #10
Changes from all commits
Commits
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 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,39 @@ | ||
#include <iostream> | ||
#include <vector> | ||
#include <algorithm> | ||
#include <functional> | ||
|
||
using namespace std; | ||
|
||
bool isAvailable(string &s) | ||
{ | ||
int sum = 0; | ||
bool isZero = false; //0이 있는지 여부 | ||
|
||
for (char c : s) | ||
{ | ||
if (c == '0') | ||
{ | ||
isZero = true; | ||
} | ||
sum += (c - '0'); | ||
} | ||
|
||
return sum % 3 == 0 && isZero; //각 자리수의 합이 3의 배수이고 0이 존재한다면 30의 배수로 만들 수 있음 | ||
} | ||
|
||
int main() | ||
{ | ||
string s; | ||
cin >> s; | ||
|
||
if (!isAvailable(s)) | ||
{ | ||
cout << -1; | ||
} | ||
else | ||
{ | ||
sort(s.begin(), s.end(), greater<char>()); //가장 큰 30의 배수로 만들기 위해 역순으로 정렬 | ||
cout << s; | ||
} | ||
} |
This file contains 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,31 @@ | ||
#include <iostream> | ||
#include <vector> | ||
#include <algorithm> | ||
|
||
using namespace std; | ||
|
||
int main() | ||
{ | ||
int n; | ||
cin >> n; | ||
|
||
vector<int> times(n, 0); | ||
|
||
for (int i = 0; i < n; i++) | ||
{ | ||
cin >> times[i]; | ||
} | ||
|
||
//돈을 인출하는 데 시간이 적게 걸리는 순으로 | ||
sort(times.begin(), times.end()); | ||
|
||
int sum = 0, tmp = 0; | ||
|
||
for (auto i : times) | ||
{ | ||
tmp += i; | ||
sum += tmp; | ||
} | ||
|
||
cout << sum; | ||
} |
This file contains 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,75 @@ | ||
#include <iostream> | ||
#include <vector> | ||
#include <string> | ||
|
||
using namespace std; | ||
|
||
bool check(string s1, string s2, int strike, int ball) | ||
{ | ||
int s = 0, b = 0; | ||
|
||
for (int i = 0; i < s1.size(); i++) | ||
{ | ||
//자리와 숫자가 모두 같다면 strike | ||
if (s1[i] == s2[i]) | ||
{ | ||
s++; | ||
} | ||
|
||
//숫자만 같은 경우에는 ball | ||
else if (s2.find(s1[i]) != string::npos) | ||
{ | ||
b++; | ||
} | ||
} | ||
|
||
return (s == strike && b == ball); | ||
} | ||
|
||
int main() | ||
{ | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
cout.tie(NULL); | ||
|
||
int n, target, s, b; | ||
vector<int> nums; | ||
|
||
//가능한 모든 경우의 수 저장 | ||
for (int i = 1; i <= 9; i++) | ||
{ | ||
for (int j = 1; j <= 9; j++) | ||
{ | ||
if (i == j) | ||
{ | ||
continue; | ||
} | ||
for (int k = 1; k <= 9; k++) | ||
{ | ||
if (i == k || j == k) | ||
{ | ||
continue; | ||
} | ||
nums.push_back(i * 100 + j * 10 + k); | ||
} | ||
} | ||
} | ||
|
||
cin >> n; | ||
|
||
while (n--) | ||
{ | ||
cin >> target >> s >> b; | ||
|
||
for (int i = nums.size() - 1; i >= 0; i--) | ||
{ | ||
//영수의 대답과 일치하지 않는 숫자를 삭제 | ||
if (!check(to_string(nums[i]), to_string(target), s, b)) | ||
{ | ||
nums.erase(nums.begin() + i); | ||
} | ||
} | ||
} | ||
|
||
cout << nums.size(); | ||
} |
This file contains 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,77 @@ | ||
#include <iostream> | ||
#include <string> | ||
#include <vector> | ||
|
||
using namespace std; | ||
|
||
void changeType(string input) | ||
{ | ||
string s = ""; | ||
int type = 0; | ||
vector<string> str; | ||
|
||
//첫 글자가 소문자가 아닌 경우 | ||
if (input[0] < 'a' || input[0] > 'z') | ||
{ | ||
cout << "Error!"; | ||
return; | ||
} | ||
|
||
for (int i = 0; i < input.size(); i++) | ||
{ | ||
if (input[i] == '_') | ||
{ | ||
str.push_back(s); | ||
s = ""; | ||
|
||
//변수명 타입이 혼용되거나 c++, java 변수명 타입에 해당되지 않는 경우 | ||
if (input[i + 1] < 'a' || input[i + 1] > 'z' || type == -1) | ||
{ | ||
cout << "Error!"; | ||
return; | ||
} | ||
|
||
s += toupper(input[++i]); | ||
type = 1; //c++ 변수명 타입이란 것을 저장 | ||
} | ||
|
||
else if (input[i] >= 'A' && input[i] <= 'Z') | ||
{ | ||
str.push_back(s + '_'); | ||
s = tolower(input[i]); | ||
|
||
//변수명 타입이 혼용되거나 c++, java 변수명 타입에 해당되지 않는 경우 | ||
if (i > input.size() - 1 && | ||
(input[i + 1] < 'a' || input[i + 1] > 'z' || type == 1)) | ||
{ | ||
cout << "Error!"; | ||
return; | ||
} | ||
|
||
type = -1; | ||
} | ||
|
||
else | ||
{ | ||
s += input[i]; | ||
} | ||
} | ||
|
||
str.push_back(s); | ||
|
||
for (string s : str) | ||
{ | ||
cout << s; | ||
} | ||
} | ||
|
||
int main() | ||
{ | ||
string input, s = ""; | ||
bool error_flag = false; | ||
int type = 0; | ||
vector<string> str; | ||
Comment on lines
+71
to
+73
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. p3. 굳이 필요하지 않은 변수 선언인 것 같습니다. |
||
|
||
cin >> input; | ||
changeType(input); | ||
} |
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.
👍👍👍