-
Notifications
You must be signed in to change notification settings - Fork 0
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
[ 스택, 큐, 덱 ] 8월 30일 #2
base: main
Are you sure you want to change the base?
The head ref may contain hidden characters: "02_\uC2A4\uD0DD_\uD050_\uB371"
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,5 @@ | ||
{ | ||
"files.associations": { | ||
"queue": "cpp" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include <iostream> | ||
#include <vector> | ||
#include <algorithm> | ||
|
||
using namespace std; | ||
|
||
bool cmp(const string &s1, const string &s2){ | ||
if(s1.size()!=s2.size()){ | ||
return s1.size()<s2.size(); | ||
} | ||
int s1_sum=0, s2_sum=0; | ||
for(int i=0;i<s1.size();i++){ | ||
if('0'<=s1[i] && s1[i]<='9'){ | ||
s1_sum+=s1[i]-'0'; | ||
} | ||
if('0'<=s2[i] && s2[i]<='9'){ | ||
s2_sum+=s2[i]-'0'; | ||
} | ||
} | ||
if(s1_sum!=s2_sum){ | ||
return s1_sum<s2_sum; | ||
} | ||
return s1<s2; | ||
} | ||
|
||
int main(){ | ||
|
||
int n; | ||
cin >> n; | ||
|
||
vector<string> arr(n); | ||
for(int i=0;i<n;i++){ | ||
cin >> arr[i]; | ||
} | ||
|
||
sort(arr.begin(), arr.end(), cmp); | ||
|
||
for(int i=0;i<arr.size();i++){ | ||
cout << arr[i] << '\n'; | ||
} | ||
|
||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include <iostream> | ||
#include <vector> | ||
#include <algorithm> | ||
|
||
using namespace std; | ||
|
||
int main(){ | ||
|
||
ios_base::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
|
||
int n, m, num; | ||
string stm; | ||
|
||
cin >> n >> m; | ||
|
||
vector<string> arr(n); | ||
for(int i=0;i<n;i++){ | ||
cin >> arr[i]; | ||
} | ||
sort(arr.begin(), arr.end()); | ||
|
||
for(int i=0;i<m;i++){ | ||
cin >> stm; | ||
if(binary_search(arr.begin(), arr.end(), stm)){ | ||
num++; | ||
} | ||
} | ||
|
||
cout << num; | ||
|
||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include <iostream> | ||
#include <cmath> | ||
|
||
using namespace std; | ||
|
||
int main(){ | ||
int w1, day_eat, diet_eat, diet_ex, n, tr; | ||
|
||
cin >> w1 >> day_eat >> tr; | ||
cin >> n >> diet_eat >> diet_ex; | ||
|
||
int day_life=day_eat; | ||
int diet_life=day_life; | ||
int w0=w1; | ||
int tr_w; | ||
|
||
for(int i=0;i<n;i++){ | ||
tr_w=diet_eat - diet_life - diet_ex; | ||
w1+=tr_w; | ||
if (abs(tr_w)>tr){ | ||
diet_life+=floor(tr_w/2.0); | ||
} | ||
w0+=diet_eat - day_life - diet_ex; | ||
} | ||
|
||
if(w0<=0){ | ||
cout<<"Danger Diet" << '\n'; | ||
} | ||
else{ | ||
cout << w0 << ' ' << day_life << '\n'; | ||
} | ||
|
||
if(diet_life<=0 || w1<=0){ | ||
cout << "Danger Diet" << '\n'; | ||
} | ||
else{ | ||
if(day_life > diet_life){ | ||
cout << w1 << ' ' << diet_life << ' ' << "YOYO" << '\n'; | ||
} | ||
else{ | ||
cout << w1 << ' ' << diet_life << ' ' << "NO" << '\n'; | ||
} | ||
} | ||
|
||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/****************************************************************************** | ||
|
||
Welcome to GDB Online. | ||
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl, | ||
C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog. | ||
Code, Compile, Run and Debug online from anywhere in world. | ||
|
||
*******************************************************************************/ | ||
#include <iostream> | ||
#include <string> | ||
|
||
using namespace std; | ||
|
||
int main() | ||
{ | ||
string a, b, ab_total; | ||
int a_digit, b_digit, a_b, ab_over=0; | ||
char ab_char; | ||
|
||
cin >> a >> b; | ||
|
||
int a_size=a.size(); | ||
int b_size=b.size(); | ||
|
||
while (a_size>0||b_size>0){ | ||
if(a_size>0){ | ||
a_digit=a[--a_size]-'0'; | ||
} | ||
else{ | ||
a_digit=0; | ||
} | ||
if(b_size>0){ | ||
b_digit=b[--b_size]-'0'; | ||
} | ||
else{ | ||
b_digit=0; | ||
} | ||
a_b=a_digit+b_digit+ab_over; | ||
ab_over=a_b/10; | ||
a_b%=10; | ||
ab_char=a_b+'0'; | ||
ab_total+=ab_char; | ||
} | ||
if(ab_over!=0){ | ||
ab_char=ab_over+'0'; | ||
ab_total+=ab_char; | ||
} | ||
|
||
for(int i=ab_total.length()-1;i>=0;i--){ | ||
cout << ab_total[i]; | ||
} | ||
|
||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <iostream> | ||
#include <queue> | ||
|
||
using namespace std; | ||
|
||
int main(){ | ||
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. main함수에서는 입출력만 넣어주시는 편이 좋습니다! 기능을 분리하여 함수로 만들어보세요! |
||
|
||
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(); | ||
} | ||
if(q.size()!=1){ | ||
cout << q.front() << ", "; | ||
q.pop(); | ||
} | ||
else{ | ||
cout << q.front() << ">"; | ||
q.pop(); | ||
} | ||
} | ||
|
||
Comment on lines
+13
to
+33
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. 로직 깔끔하고 좋은 것 같습니다! |
||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include <iostream> | ||
#include <stack> | ||
#include <string> | ||
|
||
using namespace std; | ||
|
||
int main(){ | ||
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. 마찬가지로 함수 분리해주시면 좋을 것 같네요! |
||
|
||
ios_base::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
|
||
while(true){ | ||
|
||
string str; | ||
stack<char> s; | ||
bool result=true; | ||
|
||
getline(cin, str); | ||
|
||
if(str[0]=='.'){ | ||
break; | ||
} | ||
|
||
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()=='['){ | ||
result=false; | ||
break; | ||
} | ||
else{ | ||
s.pop(); | ||
} | ||
} | ||
else if(str[i]==']'){ | ||
if(s.empty()||s.top()=='('){ | ||
result=false; | ||
break; | ||
} | ||
else{ | ||
s.pop(); | ||
} | ||
} | ||
} | ||
|
||
if(!s.empty()||result==false){ | ||
cout << "no" << '\n'; | ||
} | ||
else{ | ||
cout << "yes" << '\n'; | ||
} | ||
} | ||
|
||
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. 마찬가지로 로직 깔끔하고 좋습니다! |
||
return 0; | ||
} |
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.
덧셈의 원리를 이용해서 덧셈을 잘 구현해주셨네요!👍