U E D R , A S I H C RSS

Hartals/조현태

느낀점 및 설명

소스

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

const int NUMBER_NOMAL_DAY=2;
const int NOMAL_DAYS[NUMBER_NOMAL_DAY]={6,7};

int day_simulate(int, int, int*);

void main()
{
	int stage;
	int* mans;
	int* days;
	int** mans_days;
	printf("횟수를 입력하십시오.\n>>");
	scanf("%d",&stage);
	days=(int*)malloc(sizeof(int)*stage);
	mans=(int*)malloc(sizeof(int)*stage);
	mans_days=(int**)malloc(sizeof(int*)*stage);
	for (int i=0; i<stage; ++i)
	{
		printf("시뮬레이션 할 날의 수를 입력하십시오.\n>>");
		scanf("%d",days+i);
		printf("연합의 수를 입력하십시오.\n>>");
		scanf("%d",mans+i);
		mans_days[i]=(int*)malloc(sizeof(int)*mans[i]);
		printf("각 연합들의 파업주기를 입력하십시오.\n");
		for (int j=0; j<mans[i]; ++j)
		{
			printf(">>");
			scanf("%d",mans_days[i]+j);
		}
	}
	for (register int i=0; i<stage; ++i)
	{
		printf("%d\n",day_simulate(days[i],mans[i],mans_days[i]));
	}
	for (int i=0; i<stage; ++i)
		free(mans_days[i]);
	free(mans_days);
	free(mans);
}

int day_simulate(int input_day, int input_number_mans, int* input_mans)
{
	int play_day=0;
	for (register int i=1; i<=input_day; ++i)
	{
		register int j;
		for (j=0;j<NUMBER_NOMAL_DAY;++j)
		{
			if (0==(i-NOMAL_DAYS[j])%7)
				break;
		}
		if (j==NUMBER_NOMAL_DAY)
		{
			for (j=0;j<input_number_mans;++j)
			{
				if (0==i%input_mans[j])
				{
					++play_day;
					break;
				}
			}
		}
	}
	return play_day;
}

저에게 할말

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