-
Notifications
You must be signed in to change notification settings - Fork 0
[스택/큐/덱] 2월 26일 #2
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| #include <iostream> | ||
| #include <string> | ||
| #include <set> | ||
|
|
||
| using namespace std; | ||
| int main() { | ||
| string str; | ||
| cin >> str; | ||
| set<string> S; | ||
| int N = str.size(); | ||
| for (int i = 0; i < N; i++) { | ||
| for (int len = 1; len <= N - i; len++) { | ||
| S.insert(str.substr(i, len)); | ||
| } | ||
| } | ||
| cout << S.size(); | ||
| return 0; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| #include <iostream> | ||
| #include <cmath> | ||
| using namespace std; | ||
|
|
||
| int main() { | ||
| int W0, I0, T, D, I, A; | ||
|
|
||
| cin >> W0 >> I0 >> T; | ||
| cin >> D >> I >> A; | ||
|
|
||
| int W1 = W0; //���ʴ�緮 ��ȭ �ݿ� ���� | ||
| int W2 = W0; //���� ��緮 ��ȭ �ݿ� �� | ||
|
|
||
| int I1 = I0; //��ȭ�� ���ʴ�緮 ���� | ||
|
|
||
| for (int i = 0; i < D; i++) { | ||
| W1 += I - (I0 + A); | ||
| W2 += I - (I1 + A); | ||
| if (abs(I - (I1 + A)) > T) { | ||
| I1 += floor((I - (I1 + A)) / 2.0); | ||
| } | ||
| } | ||
| if (W1 <= 0 || I0 <= 0) { | ||
| cout << "Danger Diet\n"; | ||
| } | ||
| else { | ||
| cout << W1 << ' ' << I0 << '\n'; | ||
| } | ||
| if (W2 <= 0 || I1 <= 0) { | ||
| cout << "Danger Diet"; | ||
| } | ||
| else { | ||
| cout << W2 << ' ' << I1 << ' '; | ||
| if (I0 - I1 > 0) { | ||
| cout << "YOYO"; | ||
| } | ||
| else { | ||
| cout << "NO"; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| #include <iostream> | ||
| #include <string> | ||
| #include <algorithm> | ||
| using namespace std; | ||
|
|
||
| int main() { | ||
| string A, B; | ||
| cin >> A >> B; | ||
|
Comment on lines
+7
to
+8
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. 저희 코드 규칙에 변수는 소문자로 시작하는 camelCase, 상수는 대문자 + snake 표기법을 쓰기로 되어 있어요! 컨벤션에 맞추어 변수는 소문자로 작성해주시면 더 좋을거 같아요! 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. 죄송합니다. 변수는 소문자 snake_case입니다! |
||
|
|
||
| //�� ������ ���̸� ���� ª�� �� �տ� 0�� �߰��� | ||
| while (A.length() < B.length()) A = '0' + A; | ||
| while (B.length() < A.length()) B = '0' + B; | ||
|
Comment on lines
+11
to
+12
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. 크기를 맞추어서 자릿수 문제를 해결하신 부분 좋아요👍 |
||
|
|
||
| string result = ""; | ||
| int round = 0; //�ڸ��ø����� | ||
|
|
||
| //�ڿ��� ���� ���ʴ�� ���� | ||
| for (int i = A.length() - 1; i >= 0; i--) { | ||
| int sum = (A[i] - '0') + (B[i] - '0') + round; | ||
| round = sum / 10; //10�� ������ 1�� �ø� | ||
| result += (sum % 10) + '0'; //�ڸ��� �ϳ� �߰��� | ||
| } | ||
|
|
||
| if (round) result += '1'; //���������� �ø��� ���������� �ڸ��� �ø� | ||
|
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. 마지막 올림수까지 반영 잘 해주셨네요! |
||
| reverse(result.begin(), result.end()); //�ڿ��� ���� ��������� reverse�� ����� ��� | ||
|
|
||
| cout << result; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| #include <iostream> | ||
| #include <queue> | ||
| using namespace std; | ||
|
|
||
| int main() { | ||
| ios::sync_with_stdio(false); | ||
| cin.tie(NULL); cout.tie(NULL); | ||
|
|
||
| //N�� �Է¹ޱ� | ||
| int N; | ||
| cin >> N; | ||
|
Comment on lines
+10
to
+11
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. 컨벤션에 따라 상수명만 대문자로 작성해주시면 좋을 것 같아요! 변수와 상수를 이름만 보고도 구분이 가능하도록 하기 위함이니 참고부탁드립니다! |
||
|
|
||
| //1���� N���� ��� queue���� | ||
| queue<int> Q; | ||
|
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. 큐 자료구조를 적절히 잘 사용해주셨네요! |
||
| for (int i = 1; i <= N; i++) { | ||
| Q.push(i); | ||
| } | ||
|
|
||
| //���� ���Ǵ�� ������ �ϳ��� ���� ������ ���� | ||
|
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. 주석이 깨져있는데 인코딩 한 번 확인해보시면 좋을 것 같아요! |
||
| while (Q.size() != 1) { | ||
|
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. 틀린 표현은 아니지만 로직 상 |
||
| //���� �տ� �ִ� �� ���� | ||
| Q.pop(); | ||
| //�״������� �տ� �ִ� ���� queue�� ���� | ||
| Q.push(Q.front()); | ||
| //���� �տ� �ִ� �� ����. �̷��� ��������� �տ� �ִ� ���� �ڷ� �������� �ȴ�. | ||
| Q.pop(); | ||
|
Comment on lines
+22
to
+26
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 << Q.front(); | ||
| return 0; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| #include <iostream> | ||
| #include <string> | ||
| #include <stack> | ||
| using namespace std; | ||
|
|
||
| int main() { | ||
| ios::sync_with_stdio(false); | ||
| cin.tie(NULL); cout.tie(NULL); | ||
| while (true) { | ||
| //�ٺ��� ���� �Է¹ޱ� | ||
| string input; | ||
| getline(cin, input); | ||
|
Comment on lines
+9
to
+12
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.
|
||
|
|
||
| //.�� �ԷµǸ� while�� ������ | ||
| if (input == ".") { | ||
| break; | ||
| } | ||
| //������ ��ȣ�� ���� stack�� yes/no�� ǥ���� result ���� | ||
| stack<char> S; | ||
| bool result = true; | ||
| for (int i = 0; i < input.length(); i++) { | ||
|
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. 괄호가 균형을 이루는지 확인하는 부분은 따로 함수화하면 좋을 것 같아요! |
||
| //����ȿ� ���� ��ȣ�� ������ stack�� ���(push) | ||
| if (input[i] == '[' || input[i] == '(') { | ||
| S.push(input[i]); | ||
| } | ||
| //����ȿ� �ݴ� ��ȣ�� ������ | ||
| if (input[i] == ']') { | ||
| //stack�� ������� �ʰ�(empty()�� 0) stack�� ���� ���� ���� ¦�� ���� ��ȣ�̸� stack�� ���� ���� ���� ����(pop) | ||
| if (S.empty() == 0 && S.top() == '[') { | ||
| S.pop(); | ||
| } | ||
| //�ƴ϶�� result�� false�� �ٲٰ� while�� ���� | ||
| else { | ||
| result = false; | ||
| break; | ||
| } | ||
| } | ||
| if (input[i] == ')') { | ||
| if (S.empty() == 0 && S.top() == '(') { | ||
| S.pop(); | ||
| } | ||
| else { | ||
| result = false; | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| //stack�� ����ְ� result�� true��� yes��� | ||
| if (S.empty() == 1 && result == true) { | ||
| cout << "yes" << endl; | ||
| } | ||
| //�ƴ϶�� no��� | ||
| else { | ||
| cout << "no" << endl; | ||
| } | ||
| } | ||
| } | ||
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.
전반적으로 잘 푸셨습니다☺️
다만, 현재 github 상에서 주석이 깨져있습니다. 인코딩 문제로 보이는데, IDE에서 인코딩 형식을 바꾸어 해결할 수 있으니 링크 참고해서 설정해보세요! 설정 상 어려운 점이 있으시면 언제든지 편하게 질문해주세요!!