각종 노하우 [C를 활용한 문제해결 기법의 근간] 학습용!! 2자리소수
컨텐츠 정보
- 7 조회
- 0 추천
- 0 비추천
-
목록
본문
작성자: 작성자 없음
백준에 있는 문제로 응용된 케이스...
공부용으로 쓰세요~
#define _CRE_SECURE_NO_WARNINGS
#pragma warning(disable:4996)
#include <stdio.h>
#include <string.h>
int main(void) {
FILE *input_file = fopen("2digit_prime.inp", "r");
FILE *output_file = fopen("2digit_prime.out", "w");
int arr[21] = { 0 }; //소수 배열
int c; //조합경
int T = 0; //몇번돌림
int x = 0;//소수 보조
//char count; //받아온값 카운트에넣기
int cnt = 0; //소수일때 카운트
char buf[6] = { 0 }; // 버퍼 6칸
int a = 0; //a값 받아오기
int b = 0; //b값 받아오기
int cnt2 = 0; //a-b 까지 소수갯수
int temp = 0;
for (int q = 10; q < 100; q++) {
if (q % 2 != 0 && q % 3 != 0 && q % 5 != 0 && q % 7 != 0) {
arr[x] = q;
x++;
}
}
fscanf(input_file, "%d", &T);
for (int q = 0; q < T; q++) {
fscanf(input_file, "%d%d\n", &a, &b);
for (a; a <= b; a++) {
temp = a;
sprintf(buf, "%d", temp);//numbering은 저장할 char형 배열. a는 바꿔야 되는 int 부분.
for (int j = 0; j <strlen(buf); j++) {
if (buf[j]-48 == 0) {//십의자리0일때 걸러주고
continue;
}
for (int k = 0; k < strlen(buf); k++) {
if (buf[k]-48 == 0) {
continue;
}
//십의자리 0일때 걸러주고
if (j == k) {
continue;
}
for (int f = 0; f < 21; f++) {
c = (buf[j] - 48) * 10 + (buf[k] - 48);
if (c == arr[f]) {
cnt = 1;
break;
}
}
if (cnt == 1) {
break;
}
}
if (cnt == 1) {
break;
}
}
if (cnt == 1) {
cnt2++;
}
cnt = 0;
}
while (buf[cnt] != NULL) {
buf[cnt++] = NULL;
}
fprintf(output_file, "%d\n", cnt2);
cnt2 = 0;
}
}
-
등록일 00:20
-
등록일 08.20
-
등록일 08.10VMware 네트워크 IP 설정댓글 2
-
등록일 08.08