读书人

扑克牌解决方法

发布时间: 2012-02-06 15:52:44 作者: rapoo

扑克牌
要求是:编号为1-52张牌正面向上 从第二张开始,以2为基数,是2的倍数翻牌一次,直到最后一张牌,然后从第3张开始,以3为基数,是3的倍数翻拍一次,直到最后一张。然后……从第4张开始,以4为基数,是4的倍数翻牌一次直到最后一张牌;再依次5的倍数翻牌一次,6的,7的直到以52为基数的翻过,在输出这是正面向上的牌有哪些?
为何我
编写的这个实现不了?
请高手指点一下
谢谢……
#include "stdio.h"
#include "stdlib.h"
struct node
{
int data;
struct node *next;
};
struct node *create()
{
int x,i,n=0;
struct node *head,*p, *r;
head=(struct node *)malloc(sizeof(struct node));
p=head;
printf("input the nums\n");
scanf("%d",&x);
while(x!=-999)
{
if(x==1)
{
r=(struct node *)malloc(sizeof(struct node));
r->data=x;
p->next=r;
p=r;
}
else
{
for(i=2,n=0;i<=x;i++)
{
if(x%i==0)
n++;
}

if(n%2==0)
{
r=(struct node *)malloc(sizeof(struct node));
r->data=x;
p->next=r;
p=r;
}
else
{

r=(struct node *)malloc(sizeof(struct node));
r->data=0;
p->next=r;
p=r;
}

}
scanf("%d",&x);
}
r->next=NULL;
return(head);
}
outline(struct node *head)
{
struct node *s=head->next;
while(s!=NULL)
{
if(s->data!=0)

printf("%4d",s->data);
s=s->next;

}
}
main()
{
struct node *head;
create();
printf("正面向上的牌是\n");
outline(head);
}


[解决办法]
问题是这样的吗?这样翻了之后,很浅显的只有1那张是正面朝上的……

读书人网 >C语言

热点推荐