Home > Back-end >  About the PTA in the topic search a substring
About the PTA in the topic search a substring

Time:11-25

, well, I have a few problems to solve the problem, please help, thank you,



My code is as follows,
 

#include
# define MAXS 30
#include
Char * search (char * s, char * t)
{
Int I, k, l;
int j=0;
L=strlen (s);
I=strlen (t);
If (I - l & lt;={MAXS)
While (s [j]) {//cycle until the end of the array
If (s==t [j] [0]) {//if it is found that the first letter
For (k=1; KWhile (s [j] + k! T [k]=| | j + k> MAXS) return NULL;//pharmaceutical back the wrong letter returns null
}

Return & amp; S [j];//if you are to return to first letter address

}//if you can't find the first letter returns null
j++;
}
}
return NULL;
}
#include
# define MAXS 30

Char * search (char * s, char * t);
Void ReadString (char [] s);

Int main ()
{
Char s [MAXS], t [MAXS], * pos.

ReadString (s);
ReadString (t);

Pos=search (s, t);
If (pos!=NULL)
Printf (" % ld \ n ", pos -s);
The else
Printf (" \ n - 1 ");

return 0;
}
Void ReadString (char [] s)
{
Gets (s);
}



In the process of code compilation does not conform to one of the case, I see don't understand this situation... Please teach bosses

CodePudding user response:


This is a mistake the wrong picture

CodePudding user response:

 while (s [j] + k! T [k]=| | j + k> MAXS) return NULL; 

This statement must first determine j + k & gt; MAXS, and then judge s [j] + k! [k]=t;

 while (j + k> MAXS | | s [j] + k!=t [k]) return NULL; 


Otherwise it will lead to crossing the line,

CodePudding user response:

 while (j + k> [j] + k=MAXS | | s!=t [k]) return NULL; 

Plus a=number, otherwise can also lead to crossing the line, because j + k value is [0, MAXS 1]

CodePudding user response:

reference 3 building self-confidence boy reply:
 while (j + k> [j] + k=MAXS | | s!=t [k]) return NULL; 

Plus a=number, otherwise can also lead to crossing the line, because j + k value is [0, MAXS 1]

Bosses, hello I changed once, in my computer is no problem but submit referee program or quote that mistake,

CodePudding user response:

references and 4th floor mountains refreshment also thinks response:
Quote: refer to the third floor confident boy reply:
 while (j + k> [j] + k=MAXS | | s!=t [k]) return NULL; 

Plus a=number, otherwise can also lead to crossing the line, because j + k value is [0, MAXS 1]

Bosses, hello I changed once, in my computer is no problem but submit referee program or quote that mistake,



 if (I - l & lt; MAXS)={

This sentence make sense? I is the length of the substring, l is the source string length, then I - l'm sure less than MAXS, even if I & gt; L, so as long as no more than 30, is set up, but if I & gt; L, then you should not compare,

 char * search (char * s, char * t) 
{
Int I, k, l;
int j=0;
L=strlen (s);
I=strlen (t);
Printf (" I=% d, l=% d \ n ", I, l);
If (I & lt; L) {
While (s [j]) {//cycle until the end of the array
If (s==t [j] [0]) {//if it is found that the first letter
For (k=1; K//while (s [j] + k! T [k]=| | j + k> MAXS) return NULL;//pharmaceutical back the wrong letter returns null
While (j + k & gt;=l | | s [j] + k!=t [k]) return NULL;//pharmaceutical back the wrong letter returns null
}

Return & amp; S [j];//if you are to return to first letter address

}//if you can't find the first letter returns null
j++;
}
}
return NULL;
}


For your reference ~

If you have any questions, it is recommended that the test sample plus the input source string length is MAXS - 1 or greater than or equal to MAXS,
Input logic of the building Lord, there is no greater than or equal to the content of the input MAXS do judgment,

CodePudding user response:

Classmate is your test point I transferred out of, or a teacher gave authorization? Only right and wrong, I do the two tips, alas ~

CodePudding user response:

refer to 6th floor trustme___ response:
your classmate test point is I transferred out of, or a teacher gave authorization? Only right and wrong, I do the two tips, alas ~

Oh what do you

CodePudding user response:

references and 7th floor mountains refreshment also thinks response:
Quote: refer to the sixth floor trustme___ response:
your classmate test point is I transferred out of, or a teacher gave authorization? Only right and wrong, I do the two tips, alas ~

Oh what do you

Is the pta, but my teacher must be authorized to see the test point

CodePudding user response:

references and 7th floor mountains refreshment also thinks response:
Quote: refer to the sixth floor trustme___ response:
your classmate test point is I transferred out of, or a teacher gave authorization? Only right and wrong, I do the two tips, alas ~

Oh what do you

It doesn't matter the , different requirements for the school

CodePudding user response:

references 9 f trustme___ response:
Quote: refer to 7th floor mountains roll also thinks response:
Quote: refer to the sixth floor trustme___ response:
your classmate test point is I transferred out of, or a teacher gave authorization? nullnullnullnullnull
  • Related