Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
Tags
- /
- 도커 #docker #docker-compose.yml #도커컴포즈 #배포 #spring #mysql #docker-compose
- chatgpt #gpt #챗지피티 #ai
- 도커 #Docker #배포 #Spring #MySQL #백엔드배포
Archives
- Today
- Total
개발자 데뷔!
[C/C++ 8.1] 알고리즘 - DAT 본문
DAT : Direct Addressing Table
각 값이 저장되어있는 배열의,
해당 값을 그대로 index로 사용한 또다른 배열에
그 값의 count 개수를 저장하는 방식
int dat[10] ={0}; // DAT 에서 0초기화가 매우 중요 !!! ***
DAT 사용
- 있는 문자 표시 하기
//Level 18
//1번 // Direct Addressing Table
int main() {
char CardList[16];
int dat[100] = { 0 }; // 문자를 index로 받는 배열
int i = 0;
int cnt = 0;
cin >> CardList;
while (CardList[i] != '\0') {
dat[CardList[i]] = 1; //dat[index]가 1로 바뀜
i++;
}
//갯수(문자종류)세기
for (int i = 0; i < 100; i++) {
if (dat[i] == 1)
cnt++;
}
cout << cnt << "개";
return 0;
}
- 2차원 배열에서, 있는 숫자 개수 count 하기
//2번
int main() { // DAT 로 숫자별 등장개수세기 !!!!!!!!!!!!!!!!!! ***************************정리
int arr[3][4] = { 65000,35,42,70,70,35,65000,1300,65000,30000,38,42 };
int dat[100000] = { 0 };
int max,idx;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 4; j++) {
dat[arr[i][j]]++; //dat[index] 에 개수 세기! *index는 주어진 배열에 입력 된 값
}
}
max = 0, idx = 0;
for (int i = 0; i < 100000; i++) {
if (dat[i] > max) {
max = dat[i];
idx = i;
}
}
cout << idx;
return 0;
}
- char 2차원 배열에서 알파벳 count
//8번
int main() {
char input[3][10];
int dat[100] = { 0 }; //알파벳 count용 배열
int flag = 0;
for (int i = 0; i < 3; i++)
cin >> input[i];
//알파벳 별 숫자세기
for (int i = 0; i < 3; i++) {
int j = 0;
while (input[i][j] != '\0') {
dat[input[i][j]]++;
j++;
}
}
for (int i = 0; i < 100; i++) {
if (dat[i] > 1)
flag = 1; //2개이상 같은 게 있으면 flag 1
}
if (flag == 1)
cout << "No";
else if (flag == 0)
cout << "Perfect";
return 0;
}
등급별로 구간범위를 나누어, 구간count하기
//7번
int calcul(int lev_cnt[4],int s) { //구간별 등급 구간을 2차원 배열에 저장함
int levelTable[4][2] = { 10,20,30,60,100,150,200,300 }; // 10~20, 30~60, 100~150, 200~300
for (int i = 0; i < 4; i++) {
// 그 범위에 해당된다면,
if (levelTable[i][0] <= s && levelTable[i][1] >= s)
lev_cnt[i]++; //구간별 index그대로 써서 count
}
return 0;
}
int main() {
int lev_cnt[4] = { 0 };
// 입력받음
int calro[6];
for (int i = 0; i < 6; i++) {
cin >> calro[i];
}
//함수에 입력
for (int i = 0; i < 6; i++) {
calcul(lev_cnt, calro[i]); // 함수에 count배열 입력받기
}
//출력
for (int i = 0; i < 4; i++) {
cout << "lev" << i << ":" << lev_cnt[i]<<endl;
}
return 0;
}
'알고리즘 & 자료구조 > 알고리즘 (Algo)' 카테고리의 다른 글
| [C/C++ 8.6] 알고리즘 - 그래프(인접행렬) / DFS/ BFS (0) | 2022.04.23 |
|---|---|
| [C/C++ 8.4] 알고리즘 - Shift Left / Shift Right (0) | 2022.04.21 |
| [C/C++ 8.3] 알고리즘 - 재귀/DFS/BFS (0) | 2022.04.19 |
| [C/C++ 8.3] 알고리즘 - 재귀 (0) | 2022.03.17 |
| [C/C++ 8.2] 알고리즘 - Direct (0) | 2022.03.16 |