# include
# include
# include
Struct cell {
int x;
Char y;
Struct cell * next;
};
Int zhishu (int n) {
int i;
If (n==0 | | n==1)
return 0;
The else {
If (n==2)
return 1;
If (n==3)
return 1;
For (I=2; i<=n - 1; I++) {
If I (n %==0)
return 0;
}
return 1;
}
}
Struct cell * build (char [], int n) {
Int I, j, k, l, flag=0;
Struct head cell * and * p, * TMP * h;
The head=p=TMP=NULL;
P=(struct) cell * malloc (sizeof (struct cell));
P - & gt; Next=NULL;
P - & gt; Y=a, [0].
P - & gt; X=1;
The head=p;
TMP=p;
for(i=1; i<=n - 1; I++) {
For (h=head; H - & gt; Next!=NULL; H=h - & gt; Next) {
If (h - & gt; Y==a [I]) {
H - & gt; X=h - & gt; X + 1;
flag=1;
break;
}
}
If (flag==0) {
P=(struct) cell * malloc (sizeof (struct cell));
P - & gt; Next=NULL;
P - & gt; X=1;
P - & gt; Y=a, [I].
TMP - & gt; Next=p;
TMP=p;
}
}
return head;
}
Int maxing (struct cell * head) {
Int flag, I;
Struct cell * p;
flag=0;
While (flag==0) {
Flag==1;
For (p=head; P - & gt; Next!=NULL; P=p - & gt; Next) {
If ((p - & gt; X) & lt; (p - & gt; Next - & gt; X)) {
flag=0;
I=p - & gt; x;
P - & gt; X=p - & gt; Next - & gt; x;
P - & gt; Next - & gt; X=I;
}
}
}
Return the head - & gt; x;
}
Int mining, (struct cell * head) {
Int flag, I;
Struct cell * p;
flag=0;
While (flag==0) {
Flag==1;
For (p=head; P - & gt; Next!=NULL; P=p - & gt; Next) {
If (p - & gt; X> P - & gt; Next - & gt; X) {
flag=0;
I=p - & gt; x;
P - & gt; X=p - & gt; Next - & gt; x;
P - & gt; Next - & gt; X=I;
}
}
}
Return the head - & gt; x;
}
Void release (struct cell * head) {
If (head==NULL)
return;
The else {
Release (head - & gt; Next);
Free (the head);
}
}
Int main () {
Char a, [101].
Struct cell * head;
Int Max, min, I, j, k;
The scanf (" % s ", a);
Head=build (a, strlen (a));
Max=maxing (head);
Min=mining, (the head);
I=Max - min;
If (zhishu (I)==0)
Printf (" No Answer/n0 ");
The else {
Printf (" Lucky Word \ n ");
Printf (" % d ", I);
}
Release (the head);
}
CodePudding user response:
//flag==1;
flag=1;
Two such assignment
I can't see the code to create lists of the building Lord, direct use of linked lists, is certainly going to have a problem ~