PKU ACM 1008 题,高手看一下,为什么老是wrong answer
#include<iostream>#include<string>usingnamespacestd;intmain(){intn,i,d,y,t,num,j;char...
#include <iostream>
#include <string>
using namespace std;
int main()
{
int n,i,d,y,t,num,j;
char x;
char m[8];
char* a[19]={"pop","no","zip","zotz","tzec","xul","yoxkin","mol","chen", "yax", "zac",
"ceh","mac","kankin","muan","pax","koyab","cumhu","uayet"};
char* b[20]={"imix", "ik","akbal", "kan","chicchan","cimi","manik","lamat","muluk",
"ok","chuen","eb","ben","ix","mem","cib","caban","eznab","canac","ahau"};
cin>>n;
cout<<n<<endl;
while(n--)
{
cin>>d>>x>>m>>y;
for(i=0;i<19;i++)
if(strcmp(m,a[i])==0)
num=y*365+i*20+d+1;
y=num/260;
t=num%260;
d=t%13;
j=t%20;
strcpy(m,b[j-1]);
cout<<d<<' '<<m<<' '<<y<<endl;
}
return 0;
} 展开
#include <string>
using namespace std;
int main()
{
int n,i,d,y,t,num,j;
char x;
char m[8];
char* a[19]={"pop","no","zip","zotz","tzec","xul","yoxkin","mol","chen", "yax", "zac",
"ceh","mac","kankin","muan","pax","koyab","cumhu","uayet"};
char* b[20]={"imix", "ik","akbal", "kan","chicchan","cimi","manik","lamat","muluk",
"ok","chuen","eb","ben","ix","mem","cib","caban","eznab","canac","ahau"};
cin>>n;
cout<<n<<endl;
while(n--)
{
cin>>d>>x>>m>>y;
for(i=0;i<19;i++)
if(strcmp(m,a[i])==0)
num=y*365+i*20+d+1;
y=num/260;
t=num%260;
d=t%13;
j=t%20;
strcpy(m,b[j-1]);
cout<<d<<' '<<m<<' '<<y<<endl;
}
return 0;
} 展开
2个回答
展开全部
特殊情况没有考虑清楚:
#include <string>
using namespace std;
int main()
{
int n,i,d,y,t,num,j;
char x;
char m[8];
char* a[19]={"pop","no","zip","zotz","tzec","xul","yoxkin","mol","chen", "yax", "zac",
"ceh","mac","kankin","muan","pax","koyab","cumhu","uayet"};
char* b[20]={"imix", "ik","akbal", "kan","chicchan","cimi","manik","lamat","muluk",
"ok","chuen","eb","ben","ix","mem","cib","caban","eznab","canac","ahau"};
cin>>n;
cout<<n<<endl;
while(n--)
{
cin>>d>>x>>m>>y;
for(i=0;i<19;i++)
if(strcmp(m,a[i])==0)
num=y*365+i*20+d+1;
y=num/260;
t=num%260;
if(t==0) y--; // 漏了年底的特殊情况
d=t%13;
if(d==0) d = 13; // 新历不能是0开头
j=t%20;
if(j==0) j = 20; // 当j是0的时候, j-1就成-1了.
strcpy(m,b[j-1]);
cout<<d<<' '<<m<<' '<<y<<endl;
}
return 0;
}
#include <string>
using namespace std;
int main()
{
int n,i,d,y,t,num,j;
char x;
char m[8];
char* a[19]={"pop","no","zip","zotz","tzec","xul","yoxkin","mol","chen", "yax", "zac",
"ceh","mac","kankin","muan","pax","koyab","cumhu","uayet"};
char* b[20]={"imix", "ik","akbal", "kan","chicchan","cimi","manik","lamat","muluk",
"ok","chuen","eb","ben","ix","mem","cib","caban","eznab","canac","ahau"};
cin>>n;
cout<<n<<endl;
while(n--)
{
cin>>d>>x>>m>>y;
for(i=0;i<19;i++)
if(strcmp(m,a[i])==0)
num=y*365+i*20+d+1;
y=num/260;
t=num%260;
if(t==0) y--; // 漏了年底的特殊情况
d=t%13;
if(d==0) d = 13; // 新历不能是0开头
j=t%20;
if(j==0) j = 20; // 当j是0的时候, j-1就成-1了.
strcpy(m,b[j-1]);
cout<<d<<' '<<m<<' '<<y<<endl;
}
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询