그동안 정리는 계속 하고있었는데 강의 정리를 올리는 건 아닌거 같아서,,, 푼 문제만 업로드 하기로 했다~ 노션을 공개로 돌리기에는 다른 것들이 너어어무 많아서..ㅎㅎ
https://github.com/encrypted-def/basic-algo-lecture
GitHub - encrypted-def/basic-algo-lecture: 바킹독의 실전 알고리즘 강의 자료
바킹독의 실전 알고리즘 강의 자료. Contribute to encrypted-def/basic-algo-lecture development by creating an account on GitHub.
github.com
백준 10808번 : 알파벳 갯수
- 내가 푼 것
#include <iostream>
#include <string>
using namespace std;
int main(void){
char alp[26]={'a','b','c','d','e','f','g','h','i','j','k',
'l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
int cnt[26];
for(int i=0;i<26;i++){ //cnt 배열 0으로 초기화
cnt[i]=0;
}
string str;
cin>>str;
for(int i=0;i<str.size();i++){
for(int j=0;j<26;j++){
if(str[i]==alp[j]){
cnt[j]+=1;
}
}
}
for(int i=0;i<26;i++){
cout <<cnt[i]<<' ';
}
cout <<"\n";
}
2577번 숫자의 개수
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
int cnt[10]; // 전역변수로 설정해서 이미 0으로 초기화 되어있음
int main(void){
int a,b,c,sum=0;
cin>>a>>b>>c;
sum=a*b*c;
string str=to_string(sum);
for(auto s : str){
cnt[s-48]++;
}
for(int i=0;i<10;i++){
cout <<cnt[i]<<"\n";
}
}
1475번 : 방 번호 ✅
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
int freq[10];
int main(void){
string str;// 방번호
cin>>str;
for(auto s : str){
freq[s-48]++;
}
int num=0;
for(int i=0;i<10;i++){
if(i!=9 && i!=6)
num=max(num,freq[i]);
}
cout <<max(num,(freq[6]+freq[9]+1)/2);
cout <<"\n";
}
3273번 : 두 수의 합 - silver 3
- a1-a2=X → a2=X-a1
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
int n,x,s;
int cnt=0;
int num[2000001]={};
cin>>n;
for(int i=0;i<n;i++){
cin>>s;
num[s]++; // 해당 숫자에 cnt
}
cin>>x;
for(int i=0;i<(x+1)/2;i++){ // 배열에서 중복제거
if(num[i]==1 && num[x-i]==1){
cnt++;
}
}
cout <<cnt<<endl;
}
10807번 : 개수 세기 - bronze 5
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
int n,f,cnt=0;
int nums[101];
cin>>n;
for(int i=0;i<n;i++){
cin>>nums[i];
}
cin>>f;
for(int i=0;i<n;i++){
if(nums[i]==f){
cnt++;
}
}
cout <<cnt<<endl;
}
1330번 : 방 배정 - bronze 2
- 부분점수 2점짜리 코드
#include <iostream>
#include <string>
#include <queue>
#include <utility>
#include <algorithm>
int stu[2][7]; // 전역, 0으로 초기화
using namespace std;
int main(void){
ios::sync_with_stdio(0);
cin.tie(0);
int tol=0;
int n,k,s,y;
cin>> n>>k;
for(int i=0;i<n;i++){
cin>>s>>y;
if(s==0){ // 여자일 경우
stu[0][y]+=1;
}else if(s==1){// 남자 일 경우
stu[1][y]+=1;
}
}
for(int i=0;i<2;i++){
for(int j=1;j<7;j++){
if(stu[i][j]>0){
tol+=1;
if(stu[i][j]>k){
tol++;
}
}
}
}
cout <<tol<<"\n";
}
- 100점 코드
room+=stu[i][j]/k
if(stu[i][j]%k!=0){ room++; }
⇒ s가 0이고 6명일 경우, k=2
6/2=3 ---------------> 방 3개
⇒ s가 0이고 7명일 경우, k=2
7/2=3…1 -----------------> 방 3개 + 1개추가 ⇒ 4개
#include <iostream>
#include <string>
#include <queue>
#include <utility>
#include <algorithm>
int stu[2][7]; // 전역, 0으로 초기화
using namespace std;
int main(void){
ios::sync_with_stdio(0);
cin.tie(0);
int room=0;
int n,k,s,y;
cin>> n>>k;
for(int i=0;i<n;i++){
cin>>s>>y;
stu[s][y]++;
}
for(int i=0;i<2;i++){
for(int j=1;j<7;j++){
if(stu[i][j]>0){
room+=stu[i][j]/k;
if(stu[i][j]%k!=0){
room++;
}
}
}
}
cout <<room<<"\n";
}
1919번 : 애너그램 만들기 - bronze 2
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
string w1, w2;
int result;
int wrd[2][26];
int main(void){
ios::sync_with_stdio(0);
cin.tie(0);
cin>>w1>>w2;
for(char c:w1){
wrd[0][c-'a']++;
}
for(char c:w2){
wrd[1][c-'a']++;
}
for(int i=0;i<26;i++){
result+=abs(wrd[0][i]-wrd[1][i]); // 절대값으로 cnt
}
cout<<result<<"\n";
}
'알고리즘 > Algorithm' 카테고리의 다른 글
baekjoon python 기초 복습.. (0) | 2022.08.09 |
---|---|
바킹독 알고리즘 문제집 - 연결 리스트 (0) | 2022.06.26 |
SW Academy D1 -2 (0) | 2022.05.26 |
SW Academy D1 -1 (0) | 2022.05.25 |
Algorithm C++ [220118] :: Greedy - 2 (이것이 코딩테스트다 학습 정리) ... 추가 수정 예정... (0) | 2022.01.20 |