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

请各位帮忙看看吧,总是Runtime error。

Posted by tomfu at 2015-11-10 15:01:59 on Problem 1008
#include<iostream>
#include<list>
using namespace std;

int HaabCycle=365;
int HollyCycle=260;
string HaabName[19]={
	"pop","no","zip","zotz","tzec","xul","yoxkin","mol","chen","yax",
	"zac","ceh","mac","kankin","muan","pax","koyab","cumhu","uayet"
};
string HaabNum[20]={
	"0.","1.","2.","3.","4.",".5","6.","7.","8.","9.",
	"10.","11.","12.","13.","14.","15.","16.","17.","18.","19."
};
string HollyName[20]={
	"imix", "ik", "akbal", "kan", "chicchan", "cimi", "manik", 
	"lamat", "muluk", "ok", "chuen", "eb", "ben", "ix", "mem", 
	"cib", "caban", "eznab", "canac","ahau"
}; 
int HollyNum[13]={
	1,2,3,4,5,6,7,8,9,
	10,11,12,13
};
struct Haab
{
	string num;  
	string name;
	int year;
};
struct Tzdkin
{
	int num; 
	string name;
	int year;
};
int findString(string s,string *a ,int len)
{
	int i=0;
	for(i=0;i<len;i++)
	{
		if(!s.compare(a[i]))
		{
			break;
		}
	}
	return i;
}

void convertToHolly(struct Haab t,struct Tzdkin &tmp)
{
	int numIndex=0;
	int nameIndex=0;
	numIndex=findString(t.num,HaabNum,sizeof(HaabNum));
	nameIndex=findString(t.name,HaabName,sizeof(HaabName));
	long absDate = t.year*HaabCycle+nameIndex*20+numIndex+1;
	int Month=0;
	int Day=0;

	tmp.year=absDate/HollyCycle;
	int spareDate=absDate%HollyCycle;
	if(0==spareDate)
	{
		tmp.year--;
	}
	numIndex=spareDate%13;
	if(numIndex>0)
	{
		numIndex=numIndex-1;
	}
	else
	{
		numIndex=numIndex+13-1;
	}
	tmp.num=HollyNum[numIndex];
	nameIndex=spareDate%20;
	if(nameIndex>0)
	{
		nameIndex=nameIndex-1;
	}
	else
	{
		nameIndex=nameIndex+20-1;
	}
	tmp.name=HollyName[nameIndex];
}
void printHolly(struct Tzdkin &tmp)
{
	cout<<tmp.num<<" "<<tmp.name.c_str()<<" "<<tmp.year<<endl;
}
int main()
{
	int cc=0;
	list<struct Haab> m_list;
	list<struct Tzdkin> destList;
	list<struct Haab>::iterator it;
	list<struct Tzdkin>::iterator id;
	cin>>cc;
	while((cc--)>0)
	{
		struct Haab tmp;
		char a[10]={0};
		cin>>a;
		tmp.num=a;
		cin>>a;
		tmp.name=a;
		cin>>tmp.year;
		m_list.push_back(tmp);
	}
	for(it=m_list.begin();it!=m_list.end();it++)
	{
		struct Tzdkin tmp;
		convertToHolly((*it),tmp);
		destList.push_back(tmp);
	}
	cout<<destList.size()<<endl;
	for(id=destList.begin();id!=destList.end();id++)
	{
		printHolly(*id);
	}
	return 0;
};

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