forked from StepByStep-Algorithm/2021Fall
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request StepByStep-Algorithm#37 from CSyebin/main
speaking potato
- Loading branch information
Showing
11 changed files
with
366 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
int main(){ | ||
int N; | ||
scanf("%d", &N); | ||
|
||
int *sticks = malloc(sizeof(int) * N); | ||
|
||
int currentstick; | ||
|
||
for(int i = 0 ; i < N ; i++){ | ||
scanf("%d", ¤tstick); | ||
sticks[i] = currentstick; | ||
} | ||
|
||
int seenSticks, highestStick; | ||
seenSticks = 1; | ||
highestStick = sticks[N - 1]; | ||
|
||
for(int i = ( N - 1 ) ; i >= 0 ; i--){ | ||
if (sticks[i] > highestStick){ | ||
seenSticks++; | ||
highestStick = sticks[i]; | ||
} | ||
} | ||
|
||
printf("%d", seenSticks); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include <iostream> | ||
#include <queue> | ||
|
||
using namespace std; | ||
|
||
void main(){ | ||
priority_queue<int> maxHeap; | ||
|
||
|
||
int N; | ||
int curr; | ||
|
||
for (int i = 0 ; i < N ; i++){ | ||
cin >> curr; | ||
if(curr == 0){ | ||
if(maxHeap.empty()){ | ||
cout << curr << endl; | ||
} else { | ||
cout << maxHeap.top() << endl; | ||
maxHeap.pop(); | ||
} | ||
|
||
} else { | ||
maxHeap.push(curr); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import sys | ||
|
||
N = int(sys.stdin.readline()) | ||
|
||
|
||
for i in range(N): | ||
originline = sys.stdin.readline().split() | ||
originline.reverse() | ||
print("Case #",end = "") | ||
print((i + 1), end = "") | ||
print(": ",end = "") | ||
print(' '.join(originline)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
int main(){ | ||
int N; | ||
scanf("%d", &N); | ||
|
||
int *sticks = malloc(sizeof(int) * N); | ||
|
||
int currentstick; | ||
|
||
for(int i = 0 ; i < N ; i++){ | ||
scanf("%d", ¤tstick); | ||
sticks[i] = currentstick; | ||
} | ||
|
||
int seenSticks, highestStick; | ||
seenSticks = 1; | ||
highestStick = sticks[N - 1]; | ||
|
||
for(int i = ( N - 1 ) ; i >= 0 ; i--){ | ||
if (sticks[i] > highestStick){ | ||
seenSticks++; | ||
highestStick = sticks[i]; | ||
} | ||
} | ||
|
||
printf("%d", seenSticks); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#2752&2759 | ||
선택 정렬 이용 | ||
가장 작은 값부터 앞으로 당겨 옴 | ||
|
||
#15814 | ||
선택 정렬을 이용하여 N번째 까지만 정렬 | ||
|
||
#10814 | ||
정렬할 때 stable 해야 함 | ||
나이-이름 페어로 저장할 방법? | ||
리스트 두 개를 sort하는 것은 효율적이지 못함. | ||
1) pair 이용? | ||
|
||
->pair 이용 | ||
https://blockdmask.tistory.com/64 | ||
pair 개념 참고 | ||
https://blockdmask.tistory.com/70 | ||
vector 개념 참고 | ||
|
||
2) 구조체 이용 + stable_sort (algorithm 헤더파일) | ||
bool comp 작성 | ||
int, string 구별받아 입력하는 문제는 cin으로 해결 | ||
반복자 이용해서 출력 -> 쉽지 않다.. | ||
|
||
*compare 함수에서 비교연산자를 <= 으로 쓸 경우 stable 하게 유지되지 않았다 | ||
*iterator 이용시 iter 은 포인터이므로 구조체의 속성에 접근할 때 . 대신 -> 를 사용하여야 한다 | ||
|
||
*cin/cout 사용하니 시간초과가 떴다. | ||
ios_base :: sync_with_stdio(false); | ||
cin.tie(NULL); | ||
을 이용하여 해결했고, | ||
|
||
|
||
|
||
#10867 | ||
가장 도움이 된 곳 | ||
https://blockdmask.tistory.com/79 | ||
|
||
set의 기본적 개념 참고 | ||
|
||
|
||
set 헤더 파일에 들어있음 | ||
set < [ Data Type ] > [변수 이름]; | ||
중복이 허용되지 않는 원소(key) 의 집합. | ||
Insert 멤버 함수에 의해 삽입되면 원소는 자동으로 정렬됨 (기본 오름차순) | ||
반복자 이용할 경우 | ||
set < [Data Type] >::iterator iter_name | ||
|
||
S.begin()// 반복자를 리턴 | ||
S.end() // 맨 마지막 원소의 다음을 가리키는, 원소의 끝부분. 반복자를 리턴 | ||
S. insert() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include <iostream> | ||
#include <string> | ||
#include <vector> | ||
#include <algorithm> | ||
|
||
using namespace std; | ||
|
||
|
||
|
||
struct member { | ||
int age; | ||
string name; | ||
}; | ||
bool comp(const member &P1, const member &P2){ | ||
return P1.age < P2.age; | ||
} | ||
|
||
int main(){ | ||
ios_base :: sync_with_stdio(false); | ||
cin.tie(NULL); | ||
int N; | ||
cin >> N; | ||
|
||
vector <member> v; | ||
|
||
for(int i = 0 ; i < N ; i++){ | ||
member m; | ||
cin >> m.age >> m.name; | ||
v.push_back(m); | ||
} | ||
|
||
stable_sort(v.begin(), v.end(), comp); | ||
|
||
vector <member> ::iterator iter; | ||
|
||
for(iter = v.begin() ; iter != v.end() ; iter++){ | ||
cout << iter -> age << " " << iter -> name << '\n'; | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include <iostream> | ||
#include <string> | ||
#include <vector> | ||
#include <algorithm> | ||
|
||
using namespace std; | ||
struct member { | ||
int age; | ||
string name; | ||
}; | ||
bool comp(const member &P1, const member &P2){ | ||
return P1.age < P2.age; | ||
} | ||
|
||
int main(){ | ||
int N; | ||
scanf("%d", &N); | ||
|
||
vector <member> v; | ||
|
||
for(int i = 0 ; i < N ; i++){ | ||
member m; | ||
cin >> m.age >> m.name; | ||
v.push_back(m); | ||
} | ||
|
||
stable_sort(v.begin(), v.end(), comp); | ||
|
||
vector <member> ::iterator iter; | ||
|
||
for(iter = v.begin() ; iter != v.end() ; iter++){ | ||
cout << iter -> age << " " << iter -> name << endl; | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <iostream> | ||
#include <set> | ||
|
||
using namespace std; | ||
|
||
int main(){ | ||
int N, num; | ||
set <int> s; | ||
set <int>::iterator iter; | ||
|
||
scanf("%d",&N); | ||
for(int i = 0 ; i < N ; i++){ | ||
scanf("%d", &num); | ||
s.insert(num); | ||
} | ||
|
||
for(iter = s.begin() ; iter != s.end() ; iter++){ | ||
printf("%d ", *iter); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include <iostream> | ||
|
||
using namespace std; | ||
//selection sort up to only N, decreasing order | ||
int main(){ | ||
int T; | ||
scanf("%d",&T); | ||
int maxKey, temp; | ||
int num[10] = {0,}; | ||
int nums; | ||
|
||
for(int i = 0 ; i < T ; i++){ | ||
for(int j = 0 ; j < 10 ; j++){ | ||
//scanf("%d", &nums); | ||
//num[j] = nums; | ||
|
||
scanf("%d", &num[j]); | ||
|
||
//printf("%d ",nums); | ||
} | ||
//printf("\n"); | ||
|
||
//정리 | ||
for(int k = 0 ; k < 3 ; k++){ | ||
maxKey = k; | ||
|
||
for(int l = k + 1 ; l < 10 ; l++){ | ||
if (num[l] > num[maxKey]){ | ||
maxKey = l; | ||
} | ||
} | ||
|
||
temp = num[k]; | ||
num[k] = num[maxKey]; | ||
num[maxKey] = temp; | ||
|
||
|
||
//printf("%d ", num[k]); | ||
|
||
} | ||
|
||
printf("%d\n", num[2]); | ||
|
||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include <iostream> | ||
|
||
using namespace std; | ||
//using selection sort | ||
int main(){ | ||
int first, second, third; | ||
int num[3] = {0,}; | ||
|
||
scanf("%d%d%d", &first, &second, &third); | ||
num[0] = first; | ||
num[1] = second; | ||
num[2] = third; | ||
|
||
int minKey; | ||
int temp; | ||
|
||
for(int i = 0 ; i < 3 ; i++){ | ||
minKey = i; | ||
for(int j = i + 1 ; j < 3 ; j++){ | ||
if (num[j] < num[minKey]){ | ||
minKey = j; | ||
} | ||
} | ||
temp = num[i]; | ||
num[i] = num[minKey]; | ||
num[minKey] = temp; | ||
|
||
} | ||
|
||
|
||
printf("%d %d %d\n", num[0], num[1], num[2]); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <iostream> | ||
|
||
using namespace std; | ||
//using selection sort | ||
//1st * 3nd -> space | ||
int main(){ | ||
int first, second, third, fourth; | ||
int num[4] = {0,}; | ||
|
||
scanf("%d%d%d%d", &first, &second, &third, &fourth); | ||
num[0] = first; | ||
num[1] = second; | ||
num[2] = third; | ||
num[3] = fourth; | ||
|
||
int minKey; | ||
int temp; | ||
|
||
for(int i = 0 ; i < 3 ; i++){ | ||
minKey = i; | ||
for(int j = i + 1 ; j < 4 ; j++){ | ||
if (num[j] < num[minKey]){ | ||
minKey = j; | ||
} | ||
} | ||
temp = num[i]; | ||
num[i] = num[minKey]; | ||
num[minKey] = temp; | ||
|
||
} | ||
|
||
|
||
printf("%d", num[0] * num[2]); | ||
return 0; | ||
} |