ํฐ์คํ ๋ฆฌ ๋ทฐ
Programming/c
[2**][๊ตฌ์กฐ์ฒด] S-๋งํธ์ ๊ณ ๊ฐ๊ด๋ฆฌ๋ถ : ๊ณ ๊ฐ์ ๋ณด ์ ๋ ฅ๋ฐ์ ์ค๋ฆ์ฐจ์์ผ๋ก ์ ์ฅ, ๋ฒํธ ๊ฐ๋ค๋ฉด ์ด๋ฆ์์ผ๋ก ์ ์ฅ ํ ์ถ๋ ฅ
ํด๋์๊ทธ 2021. 5. 18. 16:37์ ๋ ฅ์์ 1
5 KimSooJin 010-1234-5678
ParkGilDong 010-2468-2468
ChungSangChul 010-1230-4567
LeeYoungHee 010-1357-2468
ChoiMyungHee 010-3458-1267 2468
์ถ๋ ฅ์์ 1
2 LeeYoungHee 010-1357-2468
3 ParkGilDong 010-2468-2468
์ฝ๋:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct customer {
char id[5];
char* name;
char* phone;
};
int main() {
struct customer* ct;
int n, cnt = 0;
char tmp1[51], tmp2[51];
int len1 = 0, len2 = 0;
char num[5], temp[5];
scanf("%d", &n);
ct = (struct customer*)malloc(n * sizeof(struct customer));
if (ct == NULL) {
printf("Not enough memory!");
return -1;
}
for (int i = 0; i < n; i++) {
scanf("%s %s", tmp1, tmp2);
len1 = strlen(tmp1);
len2 = strlen(tmp2);
(ct + i)->name = (struct customer*)malloc((len1 + 1) * sizeof(struct customer));
if ((ct + i)->name == NULL) {
printf("Not enough memory!");
return -1;
}
strcpy((ct + i)->name, tmp1);
(ct + i)->phone = (struct customer*)malloc((len2 + 1) * sizeof(struct customer));
if ((ct + i)->phone == NULL) {
printf("Not enough memory!");
return -1;
}
strcpy((ct + i)->phone, tmp2);
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (strncmp((ct + i)->phone + 9, (ct + j)->phone + 9, 4) < 0) {
strcpy(tmp1, (ct + i)->name);
strcpy((ct + i)->name, (ct + j)->name);
strcpy((ct + j)->name, tmp1);
strcpy(tmp2, (ct + i)->phone);
strcpy((ct + i)->phone, (ct + j)->phone);
strcpy((ct + j)->phone, tmp2);
}
else if (strncmp((ct + i)->phone + 9, (ct + j)->phone + 9, 4) == 0) {
if (strcmp((ct + i)->name, (ct + j)->name) < 0) {
strcpy(tmp1, (ct + i)->name);
strcpy((ct + i)->name, (ct + j)->name);
strcpy((ct + j)->name, tmp1);
strcpy(tmp2, (ct + i)->phone);
strcpy((ct + i)->phone, (ct + j)->phone);
strcpy((ct + j)->phone, tmp2);
}
}
}
}
scanf("%s", num);
for (int i = 0; i < n; i++) {
int k = 0;
int chk = 0;
int flag = 0;
for (int j = 9; j <= 12; j++) {
if (strncmp((ct + i)->phone + 9, num, 4) == 0) {
flag++;
chk = i;
}
}
if (flag == 4) {
printf("%d %s %s\n", chk + 1, (ct + chk)->name, (ct + chk)->phone);
cnt++;
}
}
if (cnt == 0)
printf("none");
for (int i = 0; i < n; i++) {
free((ct + i)->name);
free((ct + i)->phone);
}
free(ct);
return 0;
}
*4-1 ์ฝ๋์ ์ค๋ฆ์ฐจ์ & ๋ฒํธ๊ฐ์ ๋ ์ด๋ฆ์์ผ๋ก ์ถ๋ ฅํ๋ ์ฝ๋๋ง ๋ฃ์ด์ฃผ๋ฉด ๋จ
๋ฐ์ํ
'Programming > c' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๊ณต์ง์ฌํญ
์ต๊ทผ์ ์ฌ๋ผ์จ ๊ธ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
- Total
- Today
- Yesterday
๋งํฌ
TAG
- AIRUSH2023
- ์ฝํ
- ์ฝํ ์ค๋น
- ๋ ผ๋ฌธ๋ฆฌ๋ทฐ
- ๊ตฌ๊ธ์ฝ๋ฉ
- ํ ํฌ์๋ฐ
- AIRUSH
- ์ฝ๋ฉ์๋ฌ
- MYSQL
- StableDiffusion
- SQL
- C์ธ์ด
- lgaimers
- ํ์ด์ฌ
- ๋๋ฆผ๋ถ์ค
- gan
- dreambooth
- ํ๋ก๊ทธ๋๋จธ์ค
- ์ฝ๋ฉ๊ณต๋ถ
- Aimers
- SKTECHSUMMIT
- WGAN
- CLOVAX
- ์คํ ์ด๋ธ๋ํจ์
- AI์ปจํผ๋ฐ์ค
- HyperCLOVA
- ํ์ด์ฌ์ฝํ
- DALLE
- ๊ธฐ์ ์ปจํผ๋ฐ์ค
- ๋ ผ๋ฌธ์ฝ๊ธฐ
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 |
๊ธ ๋ณด๊ดํจ