Skip to content
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

[ 우선순위 큐 ] 9월 19일 #5

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
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
33 changes: 33 additions & 0 deletions 05_우선순위_큐/14235.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <iostream>
#include <queue>

using namespace std;

int main()
{
int n, a, gift;
priority_queue<int> pq;

cin >> n;

while(n--){
cin >> a;
if(a==0){
if(pq.empty()){
cout << -1 << '\n';

Choose a reason for hiding this comment

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

cout << "-1\n"; 이렇게 한번에 작성해도 돼요!

}
else{
cout << pq.top() << '\n';
pq.pop();
}
}
else{
while(a--){
cin >> gift;
pq.push(gift);
}
}
}

return 0;
}
29 changes: 29 additions & 0 deletions 05_우선순위_큐/2075.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <iostream>
#include <queue>

using namespace std;

int main()
{

ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);

int n, num;
priority_queue<int, vector<int>, greater<int>> pq;

cin >> n;

for(int i=0;i<n*n;i++){

Choose a reason for hiding this comment

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

연산 부분을 잘 구현해주셨네요~!

cin >> num;
pq.push(num);
if(pq.size() > n){
pq.pop();
}
}

cout << pq.top();

return 0;
}
49 changes: 49 additions & 0 deletions 05_우선순위_큐/2607.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <iostream>
#include <vector>

using namespace std;

const int NUM_CHARS = 26; //상수 선언

void countFreq(string word, vector<int> &freq) { //각 알파벡의 개수를 센다
for (int i = 0; i < word.length(); i++) { //받은 단어의 알파벳을 모두 돌며
freq[word[i] - 'A']++; //받은 벡터에 각 알파벳의 개수를 센다
}
}

int countDiff(string word, vector<int> original_freq) { //차이를 센다
vector<int> freq(NUM_CHARS, 0); //빈도(개수)를 세는 벡터
int diff = 0; //원본 단어와의 차이를 저장할 변수

countFreq(word, freq); // 각 알파벳의 개수 세기

for (int i = 0; i < NUM_CHARS; i++) { //알파벳 개수동안
diff += abs(original_freq[i] - freq[i]); //원본 단어와 다른 알파벳의 개수를 변수에 넣기
}
return diff; //diff를 반환
}

int main() { //메인
int N, ans=0; //입력받을 변수와 결과를 담을 변수
string original; //원본 문자열

cin >> N; //입력 받기
cin >> original; //원본 문자열 입력 받기
vector<int> original_freq(NUM_CHARS, 0); //기존 문자열에서 알파벳의 개수를 저장할 벡터

countFreq(original, original_freq); //기존 문자열의 알파벳의 개수 계산

for (int i = 1; i < N; i++) { //입력받은 n만큼 반복
string word; //비교할 문자열
cin >> word; //비교할 문자열 입력받기

int diff = countDiff(word, original_freq); //기존 문자열과의 차이 저장

if (diff == 0 || diff == 1 || diff == 2 && original.length() == word.length()) { //조건에 맞는 비슷한 단어라면
ans++; //개수 세기
}
}

cout << ans; //결과 출력
return 0; //종료
}
1 change: 1 addition & 0 deletions Altu-Bitu-HarinLee
Submodule Altu-Bitu-HarinLee added at f130cd