唐山市交警队:c语言问题

来源:百度文库 编辑:高考问答 时间:2024/04/26 09:06:09
#include "stdio.h"
#include "conio.h"
#define LEN sizeof(struct danci)
struct danci
{
struct danci *next;
char name[20];
int flag; /*0代表符号,1代表字母*/
int c;/*0代表非字母,1代表奇数字母,2代表偶数字母*/
};
main()
{
char ch='0',a[100],b[20];
int n=0,j,i,m,k;
struct danci *head,*pf,*pb;
printf("please input your sentence:\n");
while(ch!='\n')
{
ch=getchar();
a[n]=ch;
n++;
}

pb=(struct danci*)malloc(LEN);
pf=head=pb;
for(m=0;m<=n;m++)
{
if(a[m]=='\0')
{k=0;
if (a[m+1]!=' ')
{
pf=pb;
pb=(struct danci*)malloc(LEN);
pf->next=pb;
}
if(a[m+1]>'A'&&a[m+1]<' ')
{
pb->flag=0;
pb->c=pf->c;
}
else

{
pb->flag=1;
if(pf->c==1)
pb->c=2;
else pb->c=1;
}
}
else

{
if(k==0)
pb->name[k]=a[m];
else pb->name[k]=a[m];
k=k+1;

}

}
pb->next=NULL;
pb=pf=head;
while(pb->next!=NULL)
{if (pb->flag==0)
printf("%c",pb->name);
pf=pb;
pb=pb->next;
if(pb->c==1)
{
if(pf->flag==0)
printf("%c",pb->name);
else
printf(" %c",pb->name);

}
else {
k=0;
while(pb->name[k]!=NULL)
{
k=k+1;
}
for(j=k-1;j>0;j--)
printf("%c",pb->name[j]);
}
}
getchar();
getchar();

}

#include "stdio.h"
#include "conio.h"
#define LEN sizeof(struct danci)
#define NULL 0
struct danci
{
struct danci *next;
char name[20];
int flag; /*0代表符号,1代表单词单词*/
int c;/*0代表非字母,1代表奇数单词,2代表偶数单词*/
};
main()
{
char ch=0,a[100];
int n=0,j,i,m,k,flag=0;
struct danci *head=NULL,*pf=NULL,*pb=NULL;
printf("please input your sentence:\n");
while(ch!='\n')
{
ch=getchar();
a[n]=ch;
n++;
}

pb=(struct danci*)malloc(LEN);
pb->c=2;
pf=pb;
head=pb;
k=0;
for(m=0;m<n;m++)
{
if(a[m]>='A'&&a[m]<='Z'||a[m]>='a'&&a[m]<='z')
{pb->name[k++]=a[m];continue;}
if(k!=0)
{pb->name[k]=0;
pb->flag=1;

k=0;

if(flag==0)
{pb->c=1; flag=1;}
else
{pb->c=2;flag=0;}
}
pf=pb;
pb=(struct danci*)malloc(LEN);
pf->next=pb;
if(a[m]!=' '&&a[m]!='\n')
{pb->name[0]=a[m];
pb->flag=0;
pb->c=0;
pf=pb;
pb=(struct danci*)malloc(LEN);
pf->next=pb;
}
}
pb->next=NULL;
pb=pf=head;

while(pb!=NULL)
{if (pb->flag==0)
printf("%c",pb->name[0]);
else if(pb->flag==1&&pb->c==1)
printf("%s ",pb->name);
pb=pb->next;
}
}
你C语言不行a,要好好学呀!
这个程序是输出序数为奇数的英语单词,和标点符号。
在TC2.0中通过测试,如果你认为符合要求,就给我多加点分,谢了!