Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions week2/no10757
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;

}
40 changes: 40 additions & 0 deletions week2/no1158
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 << ", ";
}
}
Comment on lines +21 to +33
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2
알튜비튜에서는 main에서는 입출력만 다루는 것을 권장드리고 있어요 !
다음처럼 요세푸스 순열을 만드는 로직은 따로 함수로 빼면 좋을 것 같습니다 ㅎㅎ

if(!q.empty()){

cout << ",";
}
cout << ">\n";
return 0;
}
52 changes: 52 additions & 0 deletions week2/no4949
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;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2. 중괄호가 없으면 코드를 수정할 일이 생길 때 불편할 수 있어요. 특히, 협업할 때는 나중에 추가한 중괄호로 인해 git에서 충돌이 날 수 있답니다...!! 😱 코드가 한 줄이더라도 중괄호 넣으시는 걸 권장드립니다👍


stack<char> check;
bool isBalanced = true;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3. 변수명은 스네이크 코드 형식을 따라주세요!

int hello_world;      // 변수
int helloWorld()      // 함수
const int HELLO_WORLD // 상수


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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2. 현재 메인함수에서 많은 기능을 처리하고 있어요. 주요 기능을 함수화해두면 다른 곳에서도 재사용할 수 있답니다! 괄호의 대칭을 확인하는 별도의 함수를 만들고 메인함수는 이 함수를 호출하여 결과만 출력하도록 만들어볼까요? 🥰🥰