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
54 changes: 54 additions & 0 deletions 10757_AB
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;
}
35 changes: 35 additions & 0 deletions 1158_
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;
}
52 changes: 52 additions & 0 deletions 1431_SERIAL.cpp
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;
}
}
27 changes: 27 additions & 0 deletions 14425_SV.cpp
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;
}
39 changes: 39 additions & 0 deletions 19636_YOYO.cpp
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";
}
}
46 changes: 46 additions & 0 deletions 4949_yesno
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;
Comment on lines +14 to +15
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에서 충돌이 날 수 있답니다...!! 😱 코드가 한 줄이더라도 중괄호 넣으시는 걸 권장드립니다👍


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
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. i번째 문자 값이 반복적으로 사용되고 있네요! 변수로 만들면 코드 가독성을 높일 수 있을 것 같아요🤗🤗

if(!s.empty()&& s.top()=='[')
s.pop();
else
{
flag = false;
break;
}
}
Comment on lines +19 to +37
Copy link
Copy Markdown
Member

@sforseohn sforseohn Sep 2, 2024

Choose a reason for hiding this comment

The 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';
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.

P1. 이미 endl로 줄바꿈 문자를 출력했기 때문에 또다시 출력해줄 필요가 없어요! 코딩 테스트에서는 출력 형식이 조금만 달라도 틀렸다고 처리되기 때문에 수정하시면 좋을 것 같아요🤗🤗

}
return 0;
}
Comment on lines +7 to +46
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. 현재 메인함수에서 많은 기능을 처리하고 있어요. 주요 기능을 함수화해두면 다른 곳에서도 재사용할 수 있답니다! 괄호의 대칭을 확인하는 별도의 함수를 만들고 메인함수는 이 함수를 호출하여 결과만 출력하도록 만들어볼까요? 🥰🥰

11 changes: 11 additions & 0 deletions BOJ_1001.cpp
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 << "중도하차 안돼요!"
}