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;
} 展开
# 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;
} 展开
展开全部
runtime error一般是程序运行时数组超界造成的,你再检查检查
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
下面是我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;
}
#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;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询