-
Notifications
You must be signed in to change notification settings - Fork 0
Week 2 [스택, 덱, 큐] #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
6a623af
59666ac
087907f
a975e84
2b770df
cc3aeef
d5d098f
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,54 @@ | ||
| #include <iostream> | ||
| #include <vector> | ||
|
|
||
| using namespace std; | ||
|
|
||
| int main() | ||
| { | ||
| string a, b; | ||
| vector<int> ans; | ||
| cin >> a >> b; | ||
|
|
||
| if (a.length()>b.length()) | ||
| { | ||
| while(a.length() != b.length()) | ||
| { | ||
| b.insert(0, "0"); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| while(a.length() != b.length()) | ||
| { | ||
| a.insert(0, "0"); | ||
| } | ||
| } | ||
|
|
||
| bool isRound = 0; | ||
| int sum; | ||
| for (int i = a.length() - 1; i>=0; --i) | ||
| { | ||
| sum = (a[i] - '0' + b[i] - '0'); | ||
| if (isRound) | ||
| { | ||
| ++sum; | ||
| } | ||
| if (sum >= 10) | ||
| { | ||
| isRound = 1; | ||
| } | ||
| else | ||
| { | ||
| isRound = 0; | ||
| } | ||
| ans.push_back(sum % 10); | ||
| } | ||
| if(isRound) ans.push_back(1); | ||
|
|
||
| for (int i = ans.size() - 1; i>=0; --i) | ||
| { | ||
| cout << ans[i]; | ||
| } | ||
|
|
||
| return 0; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #include <iostream> | ||
| #include <vector> | ||
| #include <queue> | ||
|
|
||
| using namespace std; | ||
|
|
||
| int main() | ||
| { | ||
| int n, k; | ||
|
|
||
| vector<int> v; | ||
| queue<int> q; | ||
|
|
||
| cin >> n >> k; | ||
|
|
||
| for (int i = 1; i <= n; i++){ | ||
| q.push(i); | ||
| } | ||
| while(!q.empty()){ | ||
| for (int i = 0; i < k-1; i++){ | ||
| q.push(q.front()); | ||
| q.pop(); | ||
| } | ||
| v.push_back(q.front()); | ||
| q.pop(); | ||
| } | ||
|
|
||
| cout << "<"; | ||
| for (int i = 0; i < n-1; i++){ | ||
| cout << v[i] << ","; | ||
| } | ||
| cout << v[n-1] << ">"; | ||
|
|
||
| return 0; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| #include <iostream> | ||
| #include <algorithm> | ||
| #include <string> | ||
|
|
||
| using namespace std; | ||
|
|
||
| int n; | ||
| string a[1000]; | ||
|
|
||
| int integer_sum(string a){ | ||
| int length = a.length(); | ||
| int sum =0; | ||
| for(int i = 0; i <length; i++){ | ||
| if (a[i]-'0' <= 9 && a[i]-'0'>=0){ | ||
| sum += a[i] - '0'; | ||
| } | ||
| } | ||
| return sum; | ||
| } | ||
|
|
||
| bool compare (string a, string b){ | ||
| if(a.length()<b.length()){ | ||
| return 1; | ||
| } | ||
| else if (a.length()>b.length()){ | ||
| return 0; | ||
| } | ||
| else { | ||
| int sum_a = integer_sum(a); | ||
| int sum_b = integer_sum(b); | ||
|
|
||
| if (sum_a < sum_b){ | ||
| return 1; | ||
| } | ||
| else if (sum_a > sum_b) { | ||
| return 0; | ||
| } | ||
| else { | ||
| return a < b; | ||
| } | ||
| } | ||
| } | ||
| int main(){ | ||
| cin >> n; | ||
| for (int i = 0; i < n; i++){ | ||
| cin >> a[i]; | ||
| } | ||
| sort (a, a+n, compare); | ||
| for (int i = 0; i < n; i++){ | ||
| cout << a[i] << ' ' <<endl; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| #include <iostream> | ||
| #include <string> | ||
| #include <set> | ||
|
|
||
| using namespace std; | ||
|
|
||
| int n, m, cnt = 0; | ||
| set <string> s; | ||
|
|
||
| int main() | ||
| { | ||
| ios_base::sync_with_stdio(0); | ||
| cin.tie(0); | ||
|
|
||
| cin >> n >> m; | ||
| for (int i = 0; i < n; i++){ | ||
| string tmp; | ||
| cin >> tmp; | ||
| s.insert(tmp); | ||
| } | ||
| for (int i = 0; i <m; i++){ | ||
| string tmp; | ||
| cin >> tmp; | ||
| if (s.find(tmp) != s.end()) cnt++; | ||
| } | ||
| cout <<cnt; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| #include <iostream> | ||
| #include <cmath> | ||
|
|
||
| using namespace std; | ||
|
|
||
| int main(){ | ||
| int w, basic, t, day; | ||
| int d_input, d_output; | ||
|
|
||
| cin >> w >> basic >> t; | ||
| cin >> day >> d_input >> d_output; | ||
|
|
||
| int w1 = w; | ||
| int w2 = w; | ||
|
|
||
| int basic2 = basic; | ||
|
|
||
| for(int i=0; i<day; i++){ | ||
| w1 += d_input - (basic + d_output); | ||
| w2 += d_input - (basic2 + d_output); | ||
|
|
||
| if (abs(d_input - (basic2 + d_output))>t) | ||
| basic2 += floor((d_input - (basic2+d_output))/2.0); | ||
| } | ||
| if (21 <= 0) | ||
| cout << "Danger Diet\n"; | ||
| else | ||
| cout << w1 << " " << basic << "\n"; | ||
|
|
||
| if (w2 <= 0 || basic2 <= 0) | ||
| cout << "Danger Diet\n"; | ||
| else{ | ||
| cout << w2 << " " << basic2 << " "; | ||
| if (basic - basic2 > 0) | ||
| cout << "YOYO"; | ||
| else | ||
| cout << "NO"; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| #include <iostream> | ||
| #include <string> | ||
| #include <stack> | ||
|
|
||
| using namespace std; | ||
|
|
||
| int main() | ||
| { | ||
| while(1) { | ||
| stack <char> s; | ||
| string str; | ||
| getline(cin, str); | ||
|
|
||
| if (str == ".") | ||
| return 0; | ||
|
|
||
| bool flag = true; | ||
| for (int i = 0; i < str.length(); i++) { | ||
| if (str[i] == '(' || str[i] == '[') | ||
| s.push(str[i]); | ||
| else if (str[i]== ')') { | ||
| if (!s.empty()&&s.top()=='(') | ||
| s.pop(); | ||
| else { | ||
| flag = false; | ||
| break; | ||
| } | ||
| } | ||
| else if (str[i]==']'){ | ||
|
Comment on lines
+19
to
+29
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. i번째 문자 값이 반복적으로 사용되고 있네요! 변수로 만들면 코드 가독성을 높일 수 있을 것 같아요🤗🤗 |
||
| if(!s.empty()&& s.top()=='[') | ||
| s.pop(); | ||
| else | ||
| { | ||
| flag = false; | ||
| break; | ||
| } | ||
| } | ||
|
Comment on lines
+19
to
+37
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. 조건을 잘 나눠서 구현해주셨네요👍👍 |
||
| } | ||
| if (flag && s.empty()) | ||
| cout << "yes" << endl; | ||
| else | ||
| cout << "no" << endl; | ||
| cout << '\n'; | ||
|
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. P1. 이미 |
||
| } | ||
| return 0; | ||
| } | ||
|
Comment on lines
+7
to
+46
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. 현재 메인함수에서 많은 기능을 처리하고 있어요. 주요 기능을 함수화해두면 다른 곳에서도 재사용할 수 있답니다! 괄호의 대칭을 확인하는 별도의 함수를 만들고 메인함수는 이 함수를 호출하여 결과만 출력하도록 만들어볼까요? 🥰🥰 |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| #include <iostream> | ||
|
|
||
| using namespace std; | ||
|
|
||
| int main(){ | ||
| string str; | ||
| cin >> str; | ||
|
|
||
| cout << "알튜비튜 7기 화이팅!" | ||
| cout << "중도하차 안돼요!" | ||
| } |
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. 중괄호가 없으면 코드를 수정할 일이 생길 때 불편할 수 있어요. 특히, 협업할 때는 나중에 추가한 중괄호로 인해 git에서 충돌이 날 수 있답니다...!! 😱 코드가 한 줄이더라도 중괄호 넣으시는 걸 권장드립니다👍