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;
}
意法半导体(中国)投资有限公司
2023-06-12 广告
2023-06-12 广告
STM32是ARM Cortex内核单片机和微处理器市场和技术方面的佼佼者,目前提供16大产品线 (F0, G0, F1, F2, F3, G4, F4, F7, H7, MP1, L0, L1, L4, L4+,L5, WB),超过100...
点击进入详情页
本回答由意法半导体(中国)投资有限公司提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询