Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

哪位好心人帮忙看一下 几个特殊的例子也考虑了 还是WA!万分感激!

Posted by wujing at 2007-09-27 20:25:27 on Problem 1008
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string>
using namespace std;

const char* cal1[19] = {"pop","no","zip","zotz",
			"tzec","xul","yoxkin","mol",
			"chen","yax","zac","ceh",
			"mac","kankin","muan","pax",
			"koyab","cumhu","uayet"};
const char* cal2[20] = {"imix","ik","akbal","kan","chicchan",
                        "cimi","manik","lamat","muluk","ok",
                        "chuen","eb","ben","ix","mem",
		        "cib","caban","eznab","canac","ahau"};

int getMonth(const char* name)
{
	for(int i = 0; i < 19; i++)
	{
		if(strncmp(cal1[i],name,strlen(cal1[i])) == 0)
		{
			return i;
		}
	}

	return -1;
}

void main()
{
	int num = 0;
	int* sum_days = NULL;
	int numberOfTheDay = 0;
	char month[10];
	int year = 0;
	int index = 0;

	scanf("%d",&num);
	if((sum_days = (int*)malloc(sizeof(int)*num)) == NULL)
	{
		printf("malloc error!\n");
	}

	for(int i = 0; i < num; i++)
	{
		scanf("%d. %s %d",&numberOfTheDay,month,&year);

		sum_days[i] = year*365+getMonth(month)*20+numberOfTheDay+1;
	}

	printf("%d\n",num);
	for(int j = 0; j < num; j++)
	{
		year = sum_days[j]/260;
		sum_days[j] %= 260;
		if(sum_days[j] == 0)
		{
			year-=1;
			numberOfTheDay = 13;
			index = 19;
		}
		else
		{
			numberOfTheDay = sum_days[j]%13;
			index = sum_days[j]%20-1;
		}

		printf("%d %s %d\n",numberOfTheDay,cal2[index],year);
	}

	free(sum_days);
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator