Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
12
Task/Palindrome-detection/C/palindrome-detection-1.c
Normal file
12
Task/Palindrome-detection/C/palindrome-detection-1.c
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#include <string.h>
|
||||
|
||||
int palindrome(const char *s)
|
||||
{
|
||||
int i,l;
|
||||
l = strlen(s);
|
||||
for(i=0; i<l/2; i++)
|
||||
{
|
||||
if ( s[i] != s[l-i-1] ) return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
10
Task/Palindrome-detection/C/palindrome-detection-2.c
Normal file
10
Task/Palindrome-detection/C/palindrome-detection-2.c
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
int palindrome(const char *s)
|
||||
{
|
||||
const char *t; /* t is a pointer that traverses backwards from the end */
|
||||
for (t = s; *t != '\0'; t++) ; t--; /* set t to point to last character */
|
||||
while (s < t)
|
||||
{
|
||||
if ( *s++ != *t-- ) return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
6
Task/Palindrome-detection/C/palindrome-detection-3.c
Normal file
6
Task/Palindrome-detection/C/palindrome-detection-3.c
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
int palindrome_r(const char *s, int b, int e)
|
||||
{
|
||||
if ( (e - 1) <= b ) return 1;
|
||||
if ( s[b] != s[e-1] ) return 0;
|
||||
return palindrome_r(s, b+1, e-1);
|
||||
}
|
||||
15
Task/Palindrome-detection/C/palindrome-detection-4.c
Normal file
15
Task/Palindrome-detection/C/palindrome-detection-4.c
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
/* testing */
|
||||
int main()
|
||||
{
|
||||
const char *t = "ingirumimusnocteetconsumimurigni";
|
||||
const char *template = "sequence \"%s\" is%s palindrome\n";
|
||||
int l = strlen(t);
|
||||
|
||||
printf(template,
|
||||
t, palindrome(t) ? "" : "n't");
|
||||
printf(template,
|
||||
t, palindrome_r(t, 0, l) ? "" : "n't");
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue