ํฐ์คํ ๋ฆฌ ๋ทฐ
Programming/c
[2**][๊ตฌ์กฐ์ฒด] S-๋งํธ ๊ณ ๊ฐ ์ ํ๋ฒํธ๋ถ ์ ์ฅํด์ ๊ณ ๊ฐ๋ฒํธ ๊ฐ์ ๊ณ ๊ฐ ์ ๋ณด ์ถ๋ ฅ
ํด๋์๊ทธ 2021. 5. 17. 00:22
์ ๋ ฅ์์ 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 ParkGilDong 010-2468-2468
4 LeeYoungHee 010-1357-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];
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);
}
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 ((ct + i)->phone[j] == num[k]) {
flag++;
k++;
chk = i;
}
}
if (flag == 4) {
printf("%d %s %s\n", chk + 1, (ct + chk)->name, (ct + chk)->phone);
cnt++;
}
}
if (cnt == 0)
printf("none");
return 0;
}
*๊ณ ๊ฐ๋ฒํธ ๊ฐ์ ๊ฑฐ ๊ฒ์ฌํ ๋ ๋ท์๋ฆฌ ๋ค๊ฐ๋ฅผ ์ด๋ป๊ฒ ํ์ง ์ ๋จน์์. ๋ฐฐ์ดํ๊ธฐ ์จ์ ํ๊ฒ ์์ ์ฝ๋๊ณ ๋ฐฐ์ดํ๊ธฐ ์์ฐ๊ณ ๋ค์ ํด๋ณผ๊ฑฐ์
#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];
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);
}
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");
return 0;
}
**๋ฐฐ์ด ํ๊ธฐ ์์ด๊ฒ ์ด๊ฑฐ
strncmp ์ด์ฉํด์ strncmp((ct + i)->phone+9, num, 4)==0 ์ด๋ ๊ฒ ํด์ฃผ๋ฉด 9๋ฒ์งธ ์๋ฆฌ๋ถํฐ ๊ฒ์ฌ ๊ฐ๋ฅํ.
๋ฐ์ํ
'Programming > c' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๊ณต์ง์ฌํญ
์ต๊ทผ์ ์ฌ๋ผ์จ ๊ธ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
- Total
- Today
- Yesterday
๋งํฌ
TAG
- MYSQL
- C์ธ์ด
- ํ๋ก๊ทธ๋๋จธ์ค
- Aimers
- ๋ ผ๋ฌธ์ฝ๊ธฐ
- ์ฝํ
- ์ฝ๋ฉ๊ณต๋ถ
- ๊ธฐ์ ์ปจํผ๋ฐ์ค
- ๋ ผ๋ฌธ๋ฆฌ๋ทฐ
- AIRUSH
- DALLE
- gan
- HyperCLOVA
- WGAN
- SKTECHSUMMIT
- ํ์ด์ฌ
- ๊ตฌ๊ธ์ฝ๋ฉ
- AI์ปจํผ๋ฐ์ค
- lgaimers
- ์ฝ๋ฉ์๋ฌ
- dreambooth
- ์ฝํ ์ค๋น
- AIRUSH2023
- ํ์ด์ฌ์ฝํ
- ์คํ ์ด๋ธ๋ํจ์
- CLOVAX
- ํ ํฌ์๋ฐ
- ๋๋ฆผ๋ถ์ค
- StableDiffusion
- SQL
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 |
๊ธ ๋ณด๊ดํจ