-
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
[브루트포스] 9월 22일 #4
Open
minji1289
wants to merge
2
commits into
main
Choose a base branch
from
브루트포스
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.
The head ref may contain hidden characters: "\uBE0C\uB8E8\uD2B8\uD3EC\uC2A4"
Open
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 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,79 @@ | ||
#include <iostream> | ||
#include <algorithm> | ||
#include <queue> | ||
#include <vector> | ||
#include <string> | ||
|
||
using namespace std; | ||
|
||
string makeStr(queue<char>& q) { | ||
string str = ""; | ||
for (int i = 0; i < q.size(); i++) { | ||
str += q.front(); | ||
q.push(q.front()); | ||
q.pop(); | ||
} | ||
|
||
return str; | ||
} | ||
|
||
int main() { | ||
|
||
//단어의 개수 | ||
int N; | ||
//단어의 개수 입력받기 | ||
cin >> N; | ||
|
||
//단어들을 저장하기 위한 vector | ||
vector<string> v; | ||
|
||
//단어 한 줄씩 입력받기 | ||
for (int i = 0; i < N; i++) { | ||
string s; | ||
cin >> s; | ||
|
||
|
||
if (v.size() == 0) { | ||
v.push_back(s); | ||
} | ||
else { | ||
queue<char> q; | ||
//문자 비교를 위해 queue 사용 | ||
|
||
for (int k = 0; k < s.size(); k++) { | ||
q.push(s[k]); | ||
} | ||
|
||
bool same = false; | ||
//문자열이 같은지 확인하는 bool 변수 | ||
|
||
for (int j = 0; j < v.size(); j++) { | ||
for (int k = 0; k < s.size(); k++) { | ||
string compstr = makeStr(q); | ||
|
||
if (compstr == v[j]) { | ||
same = true; | ||
break; | ||
} | ||
|
||
q.push(q.front()); | ||
q.pop(); | ||
} | ||
|
||
if (same) { | ||
break; | ||
//같은 문자열이 queue에 있으면, vector에 문자열 추가 x | ||
} | ||
} | ||
|
||
if (!same) { | ||
v.push_back(s); | ||
//같은 문자열이 없으면 vector에 문자열 추가! | ||
} | ||
Comment on lines
+47
to
+72
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. 참고해주시면 좋을 것 같아서 남깁니다! |
||
} | ||
} | ||
|
||
cout << v.size() << "\n"; | ||
|
||
return 0; | ||
} |
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> | ||
using namespace std; | ||
|
||
pair<int, int> length(int r, int b) { | ||
int area = r + b; //타일의 넓이= 빨간 타일 개수 + 갈색 타일 개수 (타일은 1x1 크기이기 때문) | ||
for (int i = area; i > 0; i--) { //높이의 초기값을 넓이 (즉 r+b)로 설정하고, 이를 하나씩 줄여나가며 확인하는 반복문. | ||
if (area % i != 0) { //넓이(area)를 i(높이)로 나눈 값의 나머지가 0이 아니면, 즉 i로 나누어떨어지지 않는다면, 이는 직사각형이 아니라는 뜻 | ||
continue; //직사각형이 아니라면 넘어간다. | ||
} | ||
//area가 i로 나누어떨어진다면, 직사각형이라는 의미이므로, | ||
int w = area / i; // area=width(w)*height(l). 즉, i는 높이의 값 height(l). | ||
if (r == ((i + w) * 2 - 4)) { // '빨간 타일 r = 가장자리에 있는 테두리 타일의 개수 (높이+너비*2-4(겹치는부분))' 조건을 만족한다면, | ||
return make_pair(i, w); //높이, 너비 pair를 만들어서 리턴 | ||
} | ||
} | ||
} | ||
|
||
int main() { //메인 함수 | ||
int r, b; //r: 빨간 타일 개수, b: 갈색 타일 개수 | ||
|
||
//각 색깔별 타일 개수 입력받기 | ||
cin >> r >> b; | ||
|
||
//연산 값을 pair에 저장 | ||
pair<int, int> result = length(r, b); | ||
|
||
//위의 연산으로 인해 리턴된 pair를 출력 | ||
cout << result.first << ' ' << result.second << '\n'; //높이와 너비 출력 | ||
return 0; | ||
} |
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.
p2. 같은 로직인데 조금은 더 간편히 구현 가능할 것 같아요!
시계 방향으로 회전하기 위해선, 맨 앞 한 글자를 떼서 맨 뒤에 붙여야 하네요! 이에 딱 맞는 자료구조인 큐로 문자열을 잘 가공해주셨어요!!!😄😄
큐도 좋지만, string 클래스에는 <,>,==,+ 등과 같은 연산자들을 사용할 수 있다는 것을 상기해볼까요?
또한, 문자열 일부를 지우는 함수도 있어요!
그럼, string 자체에서도 시계 방향으로 회전이 가능하겠네요!