Demo entry 6335334

   

Submitted by anonymous on Dec 06, 2016 at 09:53
Language: C. Code size: 3.8 kB.

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include"BST.h"

#define	BUFFSIZE	100
#define	ONE		"[Error] - Code : 001"
#define	TWO		"[Error] - Code : 002"
#define	THREE	"[Error] - Code : 003"
#define	FOUR	"[Error] - Code : 004"

Node* bstRoot;
Node* Closed;


//Çмö¹øÈ£°¡ À߸øµÇ¸é °É·¯³»´Â°É ¸ÞÀο¡¼­ ±¸ÇöÇßÁö¸¸ ¸í·É¾îÀÇ ±â´É¿¡ À־ ÇÔ¼öº°·Î ±¸ÇöÇØÁÜ
void regit(int course_num, int n) {
	Node* tgtNode;
	tgtNode = BSTSearch(bstRoot, course_num);
	if (tgtNode == NULL) {
		printf(ONE);
		printf("\n");
	}
	else {
		if (GetSN(tgtNode) + n > GetSL(tgtNode)) {
			printf(TWO);
			printf("\n");
		}
		else {
			SetSN(tgtNode, GetSN(tgtNode)+n);
		}
	}

}
void cancel(int course_num, int n) {
	Node* tgtNode;
	tgtNode = BSTSearch(bstRoot, course_num);
	if (tgtNode == NULL) {
		printf(ONE);
		printf("\n");
	}
	else {
		if (GetSN(tgtNode) - n < 0) {
			printf(THREE);
			printf("\n");
		}
		else {
			SetSN(tgtNode, GetSN(tgtNode) - n);
		}
	}

}
void modify(int course_num, int n) {
	Node* tgtNode;
	tgtNode = BSTSearch(bstRoot, course_num);
	if (tgtNode == NULL) {
		printf(ONE);
		printf("\n");
	}
	else {
		if (GetSN(tgtNode) > n) {
			printf(FOUR);
			printf("\n");
		}
		else {
			SetSL(tgtNode, n);
		}
	}
}
void delete(int course_num) {
	Node* tgtNode = BSTRemove(&bstRoot,Closed, course_num);
	if (GetCN(tgtNode) != course_num) {
		printf(ONE);
		printf("\n");
	}
	else {
		Node* node;
		SetOC(tgtNode, FALSE);
		BSTInsert(&Closed, GetCNa(tgtNode), GetCN(tgtNode), GetSL(tgtNode), GetSN(tgtNode));
		//node = BSTSearch(Closed, GetCN(tgtNode));
	}
}
void check(int course_num) {
	Node* tgtNode;
	tgtNode = BSTSearch(bstRoot, course_num);
	printf("[Check] - course#: %05d, subject: %s, Apply#: %d, Restricted#: %d\n", tgtNode->course_num, tgtNode->class_name, tgtNode->stud_num, tgtNode->stud_lim);


}
void check_all() {
	printf("[CheckAll] - list of open classes\n");
	OInorderTraverse(bstRoot, Closed);
	printf("[CheckAll] - list of close classes\n");
	CInorderTraverse(Closed);
}
void quit() {
	printf("quit\n");
}
int main() {
	BSTMakeAndInit(&bstRoot);
	BSTMakeAndInit(&Closed);
	char inp[BUFFSIZE] = { 0, };
	char inp2[BUFFSIZE] = { 0 ,};
	FILE *fp;
	fp = fopen("CRMS_CourseList.txt", "r");
	

	while (fgets(inp, BUFFSIZE, fp) != NULL) {
		char *name;
		int course_num, stud_lim, stud_num;

		course_num = atoi(strtok(inp, " "));
		name = strtok(NULL, " ");
		stud_lim = atoi(strtok(NULL, " "));
		stud_num = atoi(strtok(NULL, " "));
		BSTInsert(&bstRoot,name, course_num, stud_lim, stud_num);
	}

	fp = fopen("CRMS_TestCase_06.txt", "r");

	

	while(fgets(inp2,BUFFSIZE,fp)!=NULL){
		char* cmd;
		int course_num, num;
		cmd = strtok(inp2, " ");
		if (!strncmp(cmd, "check_all", 9) || !strncmp(cmd, "quit", 4)) {

		}
		else {
			course_num = atoi(strtok(NULL, " ")); // Á¤¼ö·Îº¯È¯..
		}
		if (!strncmp(cmd, "check", 5)||!strncmp(cmd, "delete", 6)||!strncmp(cmd,"quit",4)) {

		}
		else {
			num = atoi(strtok(NULL, " "));
		}

		//À߸øµÈ Çмö¹øÈ£
		if (BSTSearch(bstRoot, course_num) == NULL && strncmp(cmd, "check_all", 9) && strncmp(cmd, "quit", 4)) {
			printf(ONE);
			printf("\n");
			continue;
		}

		if (!strncmp(cmd, "regit", 5)) {
			regit(course_num, num);
		}
		else if (!strncmp(cmd, "cancel", 6)) {
			cancel(course_num, num);
		}
		else if (!strncmp(cmd, "modify", 6)) {
			modify(course_num, num);
		}
		else if (!strncmp(cmd, "delete", 6)) {
			delete(course_num);
		}
		else if (!strncmp(cmd, "check_all", 9)) {
			check_all();
		}
		else if (!strncmp(cmd, "check", 5)) {
			check(course_num);
		}
		else if (!strncmp(cmd, "quit", 4)) {
			quit();
		}
	}
	
	getchar();
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).