-
Notifications
You must be signed in to change notification settings - Fork 0
[스택_큐_덱] 8월 27일 #1
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,32 @@ | ||
| //10757 큰 수 A+B | ||
| #include <iostream> | ||
| #include <string> | ||
| #include <algorithm> | ||
|
|
||
| using namespace std; | ||
|
|
||
| int main(){ | ||
| string A,B; | ||
| cin >> A >> B; | ||
| string result; | ||
|
|
||
| int carry = 0; | ||
| while (A.length() < B.length()) A = '0' + A; | ||
| while (B.length() < A.length()) B = '0' + B; | ||
|
|
||
| for (int i = A.length() - 1; i >= 0; --i) { | ||
| int sum = (A[i] - '0') + (B[i] - '0') + carry; | ||
| carry = sum / 10; | ||
| result += (sum % 10) + '0'; | ||
| } | ||
| if (carry) { | ||
| result += carry + '0'; | ||
| } | ||
|
|
||
| reverse(result.begin(), result.end()); | ||
|
|
||
| cout << result << endl; | ||
|
|
||
| return 0; | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| //1158번 요세푸스 문제 | ||
| #include <iostream> | ||
| #include <queue> | ||
|
|
||
| using namespace std; | ||
|
|
||
| int main() { | ||
| ios::sync_with_stdio(false); | ||
| cin.tie(NULL); cout.tie(NULL); | ||
|
|
||
| int n, k; | ||
| cin >> n >> k; | ||
|
|
||
| queue<int> q; | ||
| for (int i = 1; i <= n; ++i) { | ||
| q.push(i); | ||
| } | ||
|
|
||
| cout << "<"; | ||
|
|
||
| while (!q.empty()) { | ||
| for (int i = 1; i < k; ++i) { | ||
| q.push(q.front()); | ||
| q.pop(); | ||
| } | ||
|
|
||
| cout << q.front(); | ||
| q.pop(); | ||
|
|
||
| if (!q.empty()) { | ||
| cout << ", "; | ||
| } | ||
| } | ||
| if(!q.empty()){ | ||
|
|
||
| cout << ","; | ||
| } | ||
| cout << ">\n"; | ||
| return 0; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| //4949 균형잡힌 세상 | ||
| #include <iostream> | ||
| #include <stack> | ||
| #include <string> | ||
|
|
||
| using namespace std; | ||
|
|
||
| int main() { | ||
| ios::sync_with_stdio(false); | ||
| cin.tie(NULL); cout.tie(NULL); | ||
|
|
||
| string str; | ||
|
|
||
| while (true) { | ||
| getline(cin, str); | ||
|
|
||
| if (str == ".") break; | ||
|
Member
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. P2. 중괄호가 없으면 코드를 수정할 일이 생길 때 불편할 수 있어요. 특히, 협업할 때는 나중에 추가한 중괄호로 인해 git에서 충돌이 날 수 있답니다...!! 😱 코드가 한 줄이더라도 중괄호 넣으시는 걸 권장드립니다👍 |
||
|
|
||
| stack<char> check; | ||
| bool isBalanced = true; | ||
|
Member
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. 변수명은 스네이크 코드 형식을 따라주세요! |
||
|
|
||
| for (char ch : str) { | ||
| if (ch == '(' || ch == '[') { | ||
| check.push(ch); | ||
| } else if (ch == ')') { | ||
| if (check.empty() || check.top() != '(') { | ||
| isBalanced = false; | ||
| break; | ||
| } | ||
| check.pop(); | ||
| } else if (ch == ']') { | ||
| if (check.empty() || check.top() != '[') { | ||
|
Comment on lines
+23
to
+32
Member
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. 스택에 넣고 빼는 경우를 깔끔하게 잘 분리해주셨네요🤗🤗 |
||
| isBalanced = false; | ||
| break; | ||
| } | ||
| check.pop(); | ||
| } | ||
| } | ||
|
|
||
| if (!check.empty()) { | ||
| isBalanced = false; | ||
| } | ||
|
|
||
| if (isBalanced) { | ||
| cout << "yes\n"; | ||
| } else { | ||
| cout << "no\n"; | ||
| } | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
Comment on lines
+8
to
+52
Member
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. P2. 현재 메인함수에서 많은 기능을 처리하고 있어요. 주요 기능을 함수화해두면 다른 곳에서도 재사용할 수 있답니다! 괄호의 대칭을 확인하는 별도의 함수를 만들고 메인함수는 이 함수를 호출하여 결과만 출력하도록 만들어볼까요? 🥰🥰 |
||
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
알튜비튜에서는 main에서는 입출력만 다루는 것을 권장드리고 있어요 !
다음처럼 요세푸스 순열을 만드는 로직은 따로 함수로 빼면 좋을 것 같습니다 ㅎㅎ