diff --git a/week2/no10757 b/week2/no10757 new file mode 100644 index 0000000..16ff15e --- /dev/null +++ b/week2/no10757 @@ -0,0 +1,32 @@ +//10757 큰 수 A+B +#include +#include +#include + +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; + +} diff --git a/week2/no1158 b/week2/no1158 new file mode 100644 index 0000000..4aef10f --- /dev/null +++ b/week2/no1158 @@ -0,0 +1,40 @@ +//1158번 요세푸스 문제 +#include +#include + +using namespace std; + +int main() { + ios::sync_with_stdio(false); + cin.tie(NULL); cout.tie(NULL); + + int n, k; + cin >> n >> k; + + queue 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; +} diff --git a/week2/no4949 b/week2/no4949 new file mode 100644 index 0000000..a37b34c --- /dev/null +++ b/week2/no4949 @@ -0,0 +1,52 @@ +//4949 균형잡힌 세상 +#include +#include +#include + +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; + + stack check; + bool isBalanced = true; + + 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() != '[') { + isBalanced = false; + break; + } + check.pop(); + } + } + + if (!check.empty()) { + isBalanced = false; + } + + if (isBalanced) { + cout << "yes\n"; + } else { + cout << "no\n"; + } + } + + return 0; +}