#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#define NULL 0
//创建文字存储链表
typedef struct DLNode
{
char data;
struct DLNode *next;
}DLNode,*DLinkedList;
//输入文字
DLinkedList creat()
{
char a;
DLinkedList head,p1,p2;
head=(DLinkedList)malloc(sizeof(DLNode));
head->next=NULL; /*表头为空*/
p2=head;
printf("输入文字,以\n结束:");
scanf("%c",&a);
while(a!='\n')
{
p1=(DLinkedList)malloc(sizeof(DLNode));
p1->data=a;
p2->next=p1;
p2=p1;
scanf("%c",&a);
}
p2->next=NULL;
return head;
}
//输出文字
void print(DLinkedList head)
{
DLinkedList p;
p=head->next;
int i=0,b=1;
do
{
if(i==b*80)
{
printf("\n");
b++;
}
i++;
printf("%c",p->data);
p=p->next;
}while(p);
}
//统计数字总数
int number(DLinkedList head,int c)
{
DLinkedList p;
p=head->next;
c=0;
do
{
for(;p->data>=0&&p->data<=9;)
{
c++;
}
p=p->next;
}while(p);
return c;
}
//统计字母总数
int letter(DLinkedList head,int d)
{
DLinkedList p;
p=head->next;
d=0;
do
{
for(;(p->data>='a'&&p->data<='z')||(p->data>='A'&&p->data<='Z');)
{
d++;
}
p=p->next;
}while(p);
return d;
}
//统计空格总数
int blank(DLinkedList head,int e)
{
DLinkedList p;
p=head->next;
e=0;
do
{
for(;p->data==32;)
{
e++;
}
p=p->next;
}while(p);
return e;
}
//统计符号总数
int symbol(DLinkedList head,int f)
{
DLinkedList p;
p=head->next;
f=0;
do
{
if(p->data>=0||p->data<=9||p->data>='A'||p->data<='Z'||p->data>='a'||p->data<='z'||p->data==32)
break;
else
{
f++;
}
p=p->next;
}while(p);
return f;
}
//统计文字总数
int total(DLinkedList head,int total)
{
DLinkedList p;
p=head->next;
int A,B,C,D;
A=number(head,c);
B=letter(head,d);
C=blank(head,e);
D=symbol(head,f);
total=A+B+C+D;
return total;
}
//输入子串
DLinkedList creative()
{
char g;
DLinkedList head1,p3,p4;
head1=(DLinkedList)malloc(sizeof(DLNode));
head1->next=NULL; /*表头为空*/
p4=head1;
printf("输入子串,以\n结束:");
scanf("%c",&g);
while(g!='\n')
{
p3=(DLinkedList)malloc(sizeof(DLNode));
p3->data=g;
p4->next=p3;
p4=p3;
scanf("%c",&g);
}
p4->next=NULL;
return head1;
}
//统计子串出现的次数
int compare(DLinkedList head,DLinkedList head1,int frequency)
{
DLinkedList p5,p6;
frequency=0;
p5=head->next;
p6=head1->next;
do
{
do
{
if(p5->data==p6->data)
{
p5=p5->next;
p6=p6->next;
}
else
{
p5=p5->next;
p6=head1->next;
}
}while(p6);
frequency++;
}while(p5);
return frequency;
}
//主函数
int main()
{
DLinkedList head,head1;
head=creat();
printf("输出文字:\n");
print(head);
printf("输出数字总数为:");
number(head,c);
printf("输出字母总数为:");
letter(head,d);
printf("输出空格总数为:");
blank(head,e);
printf("输出符号总数为:");
symbol(head,f);
printf("输出文字总数为:");
total(head,total);
head1=creative();
printf("子串出现的次数为:");
compare(head,head1,frequency);
printf("Hello World!\n");
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#define NULL 0
//创建文字存储链表
typedef struct DLNode
{
char data;
struct DLNode *next;
}DLNode,*DLinkedList;
//输入文字
DLinkedList creat()
{
char a;
DLinkedList head,p1,p2;
head=(DLinkedList)malloc(sizeof(DLNode));
head->next=NULL; /*表头为空*/
p2=head;
printf("输入文字,以\n结束:");
scanf("%c",&a);
while(a!='\n')
{
p1=(DLinkedList)malloc(sizeof(DLNode));
p1->data=a;
p2->next=p1;
p2=p1;
scanf("%c",&a);
}
p2->next=NULL;
return head;
}
//输出文字
void print(DLinkedList head)
{
DLinkedList p;
p=head->next;
int i=0,b=1;
do
{
if(i==b*80)
{
printf("\n");
b++;
}
i++;
printf("%c",p->data);
p=p->next;
}while(p);
}
//统计数字总数
int number(DLinkedList head,int c)
{
DLinkedList p;
p=head->next;
c=0;
do
{
for(;p->data>=0&&p->data<=9;)
{
c++;
}
p=p->next;
}while(p);
return c;
}
//统计字母总数
int letter(DLinkedList head,int d)
{
DLinkedList p;
p=head->next;
d=0;
do
{
for(;(p->data>='a'&&p->data<='z')||(p->data>='A'&&p->data<='Z');)
{
d++;
}
p=p->next;
}while(p);
return d;
}
//统计空格总数
int blank(DLinkedList head,int e)
{
DLinkedList p;
p=head->next;
e=0;
do
{
for(;p->data==32;)
{
e++;
}
p=p->next;
}while(p);
return e;
}
//统计符号总数
int symbol(DLinkedList head,int f)
{
DLinkedList p;
p=head->next;
f=0;
do
{
if(p->data>=0||p->data<=9||p->data>='A'||p->data<='Z'||p->data>='a'||p->data<='z'||p->data==32)
break;
else
{
f++;
}
p=p->next;
}while(p);
return f;
}
//统计文字总数
int total(DLinkedList head,int total)
{
DLinkedList p;
p=head->next;
int A,B,C,D;
A=number(head,c);
B=letter(head,d);
C=blank(head,e);
D=symbol(head,f);
total=A+B+C+D;
return total;
}
//输入子串
DLinkedList creative()
{
char g;
DLinkedList head1,p3,p4;
head1=(DLinkedList)malloc(sizeof(DLNode));
head1->next=NULL; /*表头为空*/
p4=head1;
printf("输入子串,以\n结束:");
scanf("%c",&g);
while(g!='\n')
{
p3=(DLinkedList)malloc(sizeof(DLNode));
p3->data=g;
p4->next=p3;
p4=p3;
scanf("%c",&g);
}
p4->next=NULL;
return head1;
}
//统计子串出现的次数
int compare(DLinkedList head,DLinkedList head1,int frequency)
{
DLinkedList p5,p6;
frequency=0;
p5=head->next;
p6=head1->next;
do
{
do
{
if(p5->data==p6->data)
{
p5=p5->next;
p6=p6->next;
}
else
{
p5=p5->next;
p6=head1->next;
}
}while(p6);
frequency++;
}while(p5);
return frequency;
}
//主函数
int main()
{
DLinkedList head,head1;
head=creat();
printf("输出文字:\n");
print(head);
printf("输出数字总数为:");
number(head,c);
printf("输出字母总数为:");
letter(head,d);
printf("输出空格总数为:");
blank(head,e);
printf("输出符号总数为:");
symbol(head,f);
printf("输出文字总数为:");
total(head,total);
head1=creative();
printf("子串出现的次数为:");
compare(head,head1,frequency);
printf("Hello World!\n");
return 0;
}