PTA B1010 一元多项式求导
对PTA B1010中的一员多项式求导进行编码,第一次分数为16分,之后发现是没有涉及输出0 0,做改善后分数上升为22分,但是仅仅是改变了条件后原本正确的第三个测试点变为答案错误,在if(i==amounts - 1) printf("%d",tuple2[i]);语句中添加 && tuple2[i]==0,情况又会变为格式错误,原因不清楚,先留疑问,后续有能力后再解决
最高分22分
#include <cstdio>
const int MAXN = 100005;
int tuple1[MAXN];
int main()
{
int t=0;
do
{
scanf("%d",&tuple1[t]);
t++;
}while(tuple1[t-1]);
int amounts;
if(t%2==0) amounts=t-2;
else amounts = t-1;
int tuple2[amounts];
for(int i=0;i<(amounts);i++){
if(i%2==0) tuple2[i] = tuple1[i]*tuple1[i+1];
else tuple2[i] = tuple1[i] - 1;
if(i==amounts - 1) printf("%d",tuple2[i]);
else printf("%d ",tuple2[i]);
}
if(tuple2[amounts - 1]!=0) printf("%d %d",0,0);
return 0;
}
删除语段 if(tuple2[amounts - 1]!=0) printf("%d %d",0,0);得分19分
#include <cstdio>
const int MAXN = 100005;
int tuple1[MAXN];
int main()
{
int t=0;
do
{
scanf("%d",&tuple1[t]);
t++;
}while(tuple1[t-1]);
int amounts;
if(t%2==0) amounts=t-2;
else amounts = t-1;
int tuple2[amounts];
for(int i=0;i<(amounts);i++){
if(i%2==0) tuple2[i] = tuple1[i]*tuple1[i+1];
else tuple2[i] = tuple1[i] - 1;
if(i==amounts - 1) printf("%d",tuple2[i]);
else printf("%d ",tuple2[i]);
}
return 0;
}
在上面的其中一个语段添加&& tuple2[i]==0后格式显示错误