Skip to content

Commit 3462461

Browse files
committed
first commit for Baekjoon PS
1 parent d1daaf8 commit 3462461

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+3355
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.out

Baekjoon/01012Baek.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <iostream>
2+
#include <vector>
3+
4+
using namespace std;
5+
6+
int main(){
7+
int testCases;
8+
cin >> testCases;
9+
10+
for(int cases=0; cases<testCases; cases++){
11+
int M,N,K;
12+
cin >> M >> N >> K;
13+
vector<int> temp(M);
14+
// vector<vector<int> > ground(temp, 0);
15+
}
16+
17+
return 0;
18+
}

Baekjoon/01016Baek.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <iostream>
2+
#include <cmath>
3+
4+
using namespace std;
5+
6+
int main(){
7+
ios::sync_with_stdio(false);
8+
cin.tie(0);
9+
long long ret = 0;
10+
int min = 0;
11+
int max = 0;
12+
13+
14+
return 0;
15+
}

Baekjoon/01021Baek.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#include <iostream>
2+
#include <deque>
3+
#include <queue>
4+
5+
using namespace std;
6+
deque<int> dq;
7+
queue<int> q;
8+
9+
int findIndex(int num) {
10+
for(int i=0; i<dq.size(); ++i) {
11+
if (num == dq[i]) return i;
12+
}
13+
}
14+
15+
int main() {
16+
ios::sync_with_stdio(false);
17+
cin.tie(0);
18+
int m, n;
19+
cin >> m >> n;
20+
for(int i=1; i<=m; ++i){
21+
dq.push_back(i);
22+
}
23+
24+
for(int i=0; i<n; ++i) {
25+
int temp; cin >> temp;
26+
q.push(temp);
27+
}
28+
29+
int ret = 0;
30+
while(!q.empty()) {
31+
int index = findIndex(q.front());
32+
if (index > dq.size()/2) {
33+
// right
34+
while(q.front() != dq.front()) {
35+
int back = dq.back();
36+
dq.pop_back();
37+
dq.push_front(back);
38+
++ret;
39+
}
40+
} else {
41+
// left
42+
while(q.front() != dq.front()) {
43+
int front = dq.front();
44+
dq.pop_front();
45+
dq.push_back(front);
46+
++ret;
47+
}
48+
}
49+
50+
q.pop();
51+
dq.pop_front();
52+
}
53+
54+
cout << ret;
55+
return 0;
56+
}

Baekjoon/01027Baek.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <algorithm>
4+
5+
using namespace std;
6+
7+
int main(){
8+
ios::sync_with_stdio(false);
9+
cin.tie(0);
10+
int nums; cin >> nums;
11+
vector<int> v(nums);
12+
for(int i=0; i<nums; ++i){
13+
cin >> v[i];
14+
}
15+
if(v.size() == 1){
16+
cout << v[0]*v[0];
17+
return 0;
18+
}
19+
20+
sort(v.begin(), v.end());
21+
cout << v[0]*v[v.size()-1];
22+
return 0;
23+
}

Baekjoon/01124Baek.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <cmath>
4+
5+
using namespace std;
6+
7+
bool nPrime[100001];
8+
9+
vector<int> yaksoo(int n) {
10+
vector<int> ret;
11+
int localN = n;
12+
for(int i=2; ;) {
13+
if(i > n/2) break;
14+
if(localN%i != 0 || nPrime[i]) {
15+
++i;
16+
continue;
17+
}
18+
19+
localN /= i;
20+
ret.push_back(i);
21+
}
22+
23+
return ret;
24+
}
25+
26+
int main(){
27+
ios::sync_with_stdio(false);
28+
cin.tie(0);
29+
nPrime[0] = true;
30+
nPrime[1] = true;
31+
for(int i=2; i<=316; ++i){
32+
for(int j=2; i*j<=100000; ++j){
33+
nPrime[i*j] = true;
34+
}
35+
}
36+
37+
int a, b; cin >> a >> b;
38+
int ans = 0;
39+
for(int i=a; i<=b; ++i){
40+
vector<int> vec; // 약수 모음
41+
42+
vec = yaksoo(i);
43+
if(nPrime[vec.size()]) continue;
44+
ans += 1;
45+
}
46+
47+
std::cout << ans;
48+
49+
50+
return 0;
51+
}

Baekjoon/01158Baek.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include <iostream>
2+
#include <vector>
3+
4+
using namespace std;
5+
6+
int main(){
7+
ios::sync_with_stdio(false);
8+
cin.tie(NULL);
9+
int num, step;
10+
cin >> num >> step;
11+
vector<int> v;
12+
13+
for(int i=1; i<=num; i++)
14+
v.push_back(i);
15+
16+
vector<int> res;
17+
int pos = step-1;
18+
19+
while(!v.empty()){
20+
if(pos >= v.size()){
21+
pos -= v.size();
22+
continue;
23+
}
24+
else{
25+
res.push_back(v[pos]);
26+
v.erase(v.begin() + pos);
27+
pos += step-1;
28+
}
29+
}
30+
31+
cout << '<';
32+
for(auto iter=res.begin(); iter!=res.end()-1; iter++){
33+
cout << (*iter) << ", ";
34+
}
35+
cout << res[res.size()-1] << '>';
36+
37+
return 0;
38+
}

Baekjoon/01339Baek.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <map>
4+
#include <cmath>
5+
#include <vector>
6+
#include <algorithm>
7+
8+
using namespace std;
9+
10+
map<char, int> mm;
11+
vector<string> savedNum;
12+
vector<int> ans;
13+
14+
bool cmp(const pair<char, int>& a, const pair<char, int>& b) {
15+
if(a.second < b.second) return a.first < b.first;
16+
return a.second < b.second;
17+
}
18+
19+
int main() {
20+
ios::sync_with_stdio(false);
21+
cin.tie(0);
22+
int n; cin >> n;
23+
for(int i=0; i<n; ++i){
24+
string temp; cin >> temp;
25+
savedNum.push_back(temp);
26+
for(int j=temp.size()-1; j>=0; --j){
27+
mm[temp[j]] += pow(10, temp.size() - j - 1);
28+
}
29+
}
30+
31+
vector<pair<int, char>> vec;
32+
33+
34+
for(auto iter = mm.begin(); iter != mm.end(); ++iter){
35+
vec.push_back({(*iter).second, (*iter).first});
36+
}
37+
38+
sort(vec.begin(), vec.end(), greater<pair<int, char>>());
39+
map<char, int> mmm;
40+
for(int i=9, j=0; i>=0 && j<vec.size(); --i, ++j) {
41+
mmm[vec[j].second] = i;
42+
}
43+
44+
int ret = 0;
45+
46+
for(int i=0; i<savedNum.size(); ++i){
47+
int temp = 0;
48+
for(int j=0; j<savedNum[i].size(); ++j){
49+
temp = temp*10 + mmm[savedNum[i][j]];
50+
}
51+
ret += temp;
52+
}
53+
cout << ret;
54+
return 0;
55+
}

Baekjoon/01541Baek.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include <iostream>
2+
#include <string>
3+
4+
using namespace std;
5+
6+
string sen;
7+
8+
int main() {
9+
ios::sync_with_stdio(false);
10+
cin.tie(0);
11+
cin >> sen;
12+
13+
bool found = false;
14+
int pos = 0;
15+
int num = 0;
16+
int tempNum = 0;
17+
for(; pos<sen.size(); ++pos){
18+
if(sen[pos] == '-') {
19+
found = true;
20+
num += tempNum;
21+
++pos;
22+
break;
23+
}
24+
if(sen[pos] == '+') {
25+
num += tempNum;
26+
tempNum = 0;
27+
continue;
28+
}
29+
30+
tempNum = tempNum*10 + sen[pos] - '0';
31+
}
32+
if(!found) num += tempNum;
33+
34+
35+
if(found) {
36+
tempNum = 0;
37+
for(; pos<sen.size(); ++pos){
38+
if(sen[pos] > '9' || sen[pos] < '0'){
39+
num -= tempNum;
40+
tempNum = 0;
41+
continue;
42+
}
43+
44+
tempNum = tempNum*10 + sen[pos] - '0';
45+
}
46+
47+
num -= tempNum;
48+
}
49+
50+
cout << num;
51+
return 0;
52+
}

Baekjoon/01620Baek.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <iostream>
2+
#include <map>
3+
#include <string>
4+
5+
using namespace std;
6+
7+
int main(){
8+
ios::sync_with_stdio(false);
9+
cin.tie(0);
10+
int monsters, quiz;
11+
cin >> monsters >> quiz;
12+
map<string, int> book;
13+
map<int, string> book2;
14+
15+
for(int mon=1; mon<=monsters; ){
16+
string monster;
17+
cin >> monster;
18+
book2.insert({mon, monster});
19+
book.insert({monster, mon++});
20+
}
21+
22+
for(int q=0; q<quiz; q++){
23+
string mon;
24+
cin >> mon;
25+
if('0' <= mon[0] && mon[0] <= '9'){
26+
cout << book2[stoi(mon)] << "\n";
27+
}
28+
else{
29+
cout << book[mon] << "\n";
30+
}
31+
}
32+
return 0;
33+
}

0 commit comments

Comments
 (0)