더블릿 문제

언어/c언어2018. 11. 27. 13:31

http://59.23.150.58/30stair/sc/sc.php?pname=sc




# include <stdio.h>

# include <stdlib.h>

// ===============================

typedef struct node {

int element;

struct node* link;

}node, *pNode;

// ===============================

typedef struct linkedlist {

pNode headNode;

pNode tailNode;

int count;

}linkedlist, *pLinkedlist;

// ===============================

void // func (1)

_init_(linkedlist** param);

void // func (2)

_check_(linkedlist** param);

void // func (3)

_score_(linkedlist** param);

// ===============================

int 

main(void) {

int nNumber = 0x0;

pLinkedlist sNode = NULL;

pNode newInsrt = NULL;

sNode = (pLinkedlist)malloc(sizeof(linkedlist));

if (sNode == NULL) { exit(1); }

_init_(&sNode); // [데이터 초기화]


for (;;) {

scanf("%d", &nNumber);

if (nNumber == -1) { break; }

else { // nNumber != -1

newInsrt = (pNode)malloc(sizeof(node));

if (newInsrt == NULL) { exit(1); }

newInsrt->element = nNumber;

newInsrt->link = NULL;

if (sNode->count == 0) {

sNode->headNode->link = newInsrt;

sNode->tailNode->link = newInsrt;

sNode->count += 1;

}

else {

sNode->tailNode->link->link = newInsrt;

sNode->tailNode->link = newInsrt;

sNode->count += 1;

}

newInsrt = NULL;

}

}

//_check_(&sNode)

_score_(&sNode);

free(sNode);

return 0;

} // end of main function

  // ===============================

void // func (1)

_init_(linkedlist** param) {

(*param)->headNode = NULL;

(*param)->tailNode = NULL;

(*param)->headNode = (pNode)malloc(sizeof(node));

(*param)->tailNode = (pNode)malloc(sizeof(node));

(*param)->count = 0x0;

if ((*param)->headNode == NULL || (*param)->tailNode == NULL) { exit(1); }

else {

// headNode

(*param)->headNode->element = 0x0;

(*param)->headNode->link = NULL;

// tailNode

(*param)->tailNode->element = 0x0;

(*param)->tailNode->link = NULL;

}

} // end of _init_ function 

  // ===============================

void // func (2)

_check_(linkedlist** param) {

pNode tmpIndx = NULL;

int i;

if ((*param)->count == 0) { printf("출력할 데이터가 없습니다.\n"); }

else {

// (*param)->count != 0

tmpIndx = (*param)->headNode;

for (i = 0; i < (*param)->count; i++) {

tmpIndx = tmpIndx->link;

printf("%d\n", tmpIndx->element);

}

}

} // end of _check_ function

  // ===============================

void // func (3)

_score_(linkedlist** param) {

/*

A : 90 ~ 100

B : 80 ~ 89

C : 70 ~ 79

D : 60 ~ 69

F : 그 외

*/

pNode tmpIndx = NULL;

int i;

int A_score = 0x0;

int B_score = 0x0;

int C_score = 0x0;

int D_score = 0x0;

int F_score = 0x0;

if ((*param)->count == 0) { printf("출력할 데이터가 없습니다.\n"); }

else {

// (*param)->count != 0

printf("%d\n", (*param)->count);

tmpIndx = (*param)->headNode;

for (i = 0; i < (*param)->count; i++) {

tmpIndx = tmpIndx->link;

//printf("%d\n", tmpIndx->element);

switch (tmpIndx->element/10) {

case 10:

case 9:

++A_score; break;

case 8:

++B_score; break;

case 7:

++C_score; break;

case 6:

++D_score; break;

default:

++F_score; break;

}

}

printf("%d\n", A_score);

printf("%d\n", B_score);

printf("%d\n", C_score);

printf("%d\n", D_score);

printf("%d\n", F_score);

}

} // end of _score_ function 

'언어 > c언어' 카테고리의 다른 글

네이버 문제 풀이 - 최대공약수  (0) 2018.11.28
네이버 지식이 풀이  (0) 2018.11.28
네이버 지식인 풀이 (c)  (0) 2018.11.24
네이버 지식인 풀이  (0) 2018.11.22
네이버 풀이  (0) 2018.11.19