티스토리 뷰
1. 문제
https://www.acmicpc.net/problem/9506
2. 풀이
#include <stdio.h>
#include <stdlib.h>
#define SIZE 1000
typedef struct
{
int data[SIZE];
int front, rear;
} QueueType;
void init(QueueType *Q)
{
Q->front = Q->rear = -1;
}
int isEmpty(QueueType *Q)
{
return Q->front == Q->rear;
}
int isFull(QueueType *Q)
{
return Q->rear == SIZE-1;
}
void enqueue(QueueType *Q, int e){
if(!isFull(Q)){
Q->rear++;
Q->data[Q->rear] = e;
} else {
return -1;
}
}
int dequeue(QueueType *Q){
if(!isEmpty(Q)){
Q->front++;
return Q->data[Q->front];
} else {
return -1;
}
}
int main(void){
while(1){
int total = 0;
int length = 0;
int digit;
scanf("%d", &digit);
if(digit == -1){ break; }
QueueType resultQ;
init(&resultQ);
for(int i = 1; i < digit; i++){
if(digit % i == 0){
enqueue(&resultQ, i);
length ++;
total += i;
}
}
if(total == digit){
printf("%d = ", digit);
for(int i = 0; i < length; i ++){
if(i != length-1){
printf("%d + ", dequeue(&resultQ));
} else {
printf("%d\n", dequeue(&resultQ));
}
}
} else {
printf("%d is NOT perfect.\n", digit);
}
}
}
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 붙임성 좋은 총총이
- SWLIfeCycle
- SW생명주기
- 백준
- python
- C언어
- 브라우저뜻
- 피보나치수5
- 배수와약수
- 26069
- 알고리즘
- 브라우저
- 25304
- 삼각형과세변
- 베라의 패션
- 4779
- 25314
- 다음소수
- 점근적표기
- 데이터추상화
- 칸토어 집합
- 직사각형
- 약수
- 과제안내신분
- C99
- 27323
- 파이썬
- 배수
- 약수들의합
- 개발계발
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함