POJ 1008 C++ 在VC++ 上面运行没错, 但是在POJ 上面运行就出现runtime error. 为什么啦!!

#include<iostream>#include<string>usingnamespacestd;intmain(){stringmonthOfHaab[19]={... # include <iostream>
# include <string>
using namespace std;

int main()
{
string monthOfHaab[19] = {"pop", "no", "zip", "zotz", "tzec", "xul", "yoxkin", "mol", "chen",
"yax", "zac", "ceh", "mac", "kankin", "muan", "pax", "koyab", "cumhu", "uayet"};

string dayOfTzolkin[20] = {"imix", "ik", "akbal", "kan", "chicchan", "cimi", "manik", "lamat",
"muluk", "ok", "chuen", "eb", "ben", "ix", "mem", "cib", "caban", "eznab", "canac", "ahau"};

int num; //存输入的年月组数
cin >> num;

int total[100];

for (int i = 0; i < num; i++)
{
string day1; //输入日期
cin >> day1;

int day;

if (day1.size() == 2)
{
day = day1[0] - '0';
}
else day = (day1[0] - '0') * 10 + day1[1] - '0';

string month; //输入月份
cin >> month;

int year; //输入年份
cin >> year;

//求HAAb年里的总天数
int totalDays = 0;
totalDays += 365 * year;

int j;
for (j = 0; j < 19; j++)
{
if (month == monthOfHaab[j])
break;
}
totalDays += j * 20;
totalDays += ++day;
total[i] = totalDays;
}

cout << num << endl;

for (int h = 0; h < num; h++)
{
//obtain the year
int year1;
int remainingDays;
year1 = total[h] / 260;
remainingDays = total[h] % 260;

//obtain num
int number;
number = ((remainingDays % 13 == 0) ? 13 : (remainingDays % 13));

//obtain name of the day
string nameOfTheDay;
int k = remainingDays % 20;
if (k == 0)
nameOfTheDay = dayOfTzolkin[19];
else
nameOfTheDay = dayOfTzolkin[k - 1];

cout << number << " " << nameOfTheDay << " " << year1 << endl;
}
return 0;
}
展开
 我来答
化春海02x
2012-02-08 · TA获得超过492个赞
知道小有建树答主
回答量:271
采纳率:0%
帮助的人:170万
展开全部
runtime error一般是程序运行时数组超界造成的,你再检查检查
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
徐辉高手
2012-02-20
知道答主
回答量:4
采纳率:0%
帮助的人:3.2万
展开全部
下面是我AC的代码,你对比看看吧
#include<stdio.h>
#include<string.h>
int main()
{
char a[19][20]={"pop","no","zip","zotz","tzec","xul","yoxkin","mol","chen","yax","zac","ceh","mac","kankin","muan","pax","koyab","cumhu","uayet"};
char b[20][20]={"imix","ik","akbal","kan","chicchan","cimi","manik","lamat","muluk","ok","chuen","eb","ben","ix","mem","cib","caban","eznab","canac","ahau"};
char ch[20];
int x,y,t,n,i;
scanf("%d",&n);
printf("%d\n",n);
while(n--)
{
long sum=0;
scanf("%d. %s %d",&x,ch,&y);
sum=sum+365*y+x+1;
for(i=0;i<19;i++)
{
if(strcmp(ch,a[i])==0)
{
sum=sum+20*i;
}
}
t=sum/260;
if(sum%260==0)t=t-1;/注意这里/
sum=sum-260*t;
x=sum%13;
if(x==0)x=13;
else x=sum%13;
y=sum%20;
if(y==0)y=19;
else y=sum%20-1;
printf("%d %s %d\n",x,b[y],t);
}
return 0;
}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式