上面那个测试点始终过不去,也不知道代码哪里有问题,求高手解答!!感激不尽!
下面是我的代码:
#include<iostream>
#include<cstdlib>
using namespace std;
struct item{
int x;
int z;
struct item *next;
};
void output(item *head){
item *p=head;
while(p!=NULL){
if(p->x==0&&p->z==0){
cout<<0<<" "<<0;
break;
}
p->x=(p->x)*(p->z);
p->z--;
if(p->x!=0){
if(p==head){
cout<<p->x<<" "<<p->z;
}else{
cout<<" "<<p->x<<" "<<p->z;
}
}
p=p->next;
}
}
int main(){
int a,b;
char ch;
int count=0;
item *head=NULL;
item *node=NULL;
item *end=head;
do{
scanf("%d %d%c",&a,&b,&ch);
node=(item*)malloc(sizeof(item));
node->x=a;
node->z=b;
node->next=NULL;
if(count==0){
head=node;
end=node;
}else{
end->next=node;
end=end->next;
}
count++;
}
while(ch!='\n');
output(head);
return 0;
}