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
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];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1
string이 아닌 vector를 사용해서 main 함수에 n개만큼 초기화해준다면 메모리 측면에서도 효율적이고 훨씬 더 코드가 간결해져요 !


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){
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
isdigit 함수를 사용하면 숫자의 여부를 바로 확인할 수 있어요 !

sum += a[i] - '0';
}
}
return sum;
}

bool compare (string a, string b){
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

cmp 함수의 경우, 두 인자를 비교하기 때문에 중간에 값이 바뀌지 않도록 상수로 선언하는 것을 권장 드리며 단순히 값을 복사하는 것이 아닌 포인터로 값을 정확히 가져오는 것을 추천드립니다.
bool compare(const string& a, const 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;
}
}
Comment on lines +22 to +41
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
둘의 길이가 같지 않음을 기준으로 한다면 if문이 깊어지지 않고 코드가 간결해질 수 있어요 !

}
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;
Comment on lines +7 to +8
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
알튜비튜에서는 작업 시 발생할 수 있는 혼란을 막기 위해 전역변수 사용을 최대한 지양하고 있습니다!
이 문제의 경우에는 지역변수로 둔 뒤, 매개변수로 넘겨서도 충분히 문제를 해결할 수 있을 것 같아요 👍

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

탐색에 용이한 셋 자료구조를 사용해서 문제를 효율적으로 해결해주셨네요!


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++;
}
Comment on lines +21 to +25
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3
알튜비튜에서는 입출력을 제외한 코드는 다른 함수로 분리하는 것을 권장하고 있습니다.
입출력은 메인에 두고, 탐색하는 부분은 findString과 같은 이름의 함수로 분리하면 더 좋을 것 같아요!👍

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";
}
}
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 << "중도하차 안돼요!"
}