U E D R , A S I H C RSS

Contest Score Board/조현태

느낀점 및 설명

이번 문제의 풀이의 자료구조는 링크드 리스트..
역시 나의 자료구조의 기본은 배열 아니면 링크드 리스트 인것 같다.ㅎ
사실 배열로 작성하려고 했으나.. 왠지 링크드 리스트가 더 어울릴 것 같고.. 배열의 장점을 살릴 수 없을 것 같아서 링크드리스트로 했다.
문제를 다 읽어도 입력되는 자료의 2번째가 무엇을 뜻하는지 이해하지 못하는 불상사..(;;)가 있었으나 몰라도 잘 풀어진다는 특징이..;;;
뭐.. 일단은 테스트도 잘 되니 좋은게 좋은거라고 생각하며 넘어가겠다..후후후..ㅎ
그럼 좋은하루 되시길..ㅎ

소스

~cpp 
#include <stdio.h>
#include <iostream>

struct datas{
	int team_number;
	int score;
	int used_time;
	datas* prv;
	datas* next;
};

void input_data();
datas* such_and_malloc_point(int);
void print_data();
void free_data();

datas* start_point=NULL;
datas* end_point=NULL;

const int WRONG_TIME=20;

void main()
{
	int test_number;
	printf("몇번 테스트 하시겠습니까?");
	scanf ("%d",&test_number);
	while (test_number!=0)
	{
		printf("\n");
		input_data();
		print_data();
		free_data();
		--test_number;
	}
}

void input_data()
{
	printf("데이터를 입력해 주세요.맨 앞이 0은 취소\n");
	while(1)
	{
		int input_team_number, input_temp, input_time;	char input_e;
		printf(">>");
		scanf("%d %d %d %c",&input_team_number, &input_temp, &input_time, &input_e);
		if (input_team_number==0)
			break;
		datas* temp_point;
		if ('C'==input_e)
		{
			temp_point=such_and_malloc_point(input_team_number);
			++temp_point->score;
			temp_point->used_time+=input_time;
		}
		else if ('I'==input_e)
		{
			temp_point=such_and_malloc_point(input_team_number);
			temp_point->used_time+=WRONG_TIME;
		}
	}
}

datas* such_and_malloc_point(int target_team_number)
{
	datas* temp_point=start_point;
	while (temp_point!=NULL)
	{
		if (target_team_number==temp_point->team_number)
			return temp_point;
		temp_point=temp_point->next;
	}
	temp_point=(datas*)malloc(sizeof(datas));
	temp_point->prv=end_point;
	if (start_point==NULL)
		start_point=temp_point;
	else
		end_point->next=temp_point;
	end_point=temp_point;
	temp_point->team_number=target_team_number;
	temp_point->score=0;
	temp_point->used_time=0;
	temp_point->next=NULL;
	return temp_point;
}

void print_data()
{
	datas* temp_point=start_point;
	printf("참가 팀 번호\t푼 문제 개수\t누적된 시간 벌점\n");
	while (temp_point!=NULL)
	{
		printf("%d\t%d\t%d\n",temp_point->team_number,temp_point->score,temp_point->used_time);
		temp_point=temp_point->next;
	}
}

void free_data()
{
	datas* temp_point=start_point;
	if (temp_point!=NULL)
	{
		while (temp_point->next!=NULL)
		{
			temp_point=temp_point->next;
			free(temp_point->prv);
		}
		free(temp_point);
	}
}

저에게 할말

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:00
Processing time 0.0089 sec