Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
41
Task/Pangram-checker/C/pangram-checker-1.c
Normal file
41
Task/Pangram-checker/C/pangram-checker-1.c
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int is_pangram(const char *s)
|
||||
{
|
||||
const char *alpha = ""
|
||||
"abcdefghjiklmnopqrstuvwxyz"
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
|
||||
char ch, wasused[26] = {0};
|
||||
int total = 0;
|
||||
|
||||
while ((ch = *s++) != '\0') {
|
||||
const char *p;
|
||||
int idx;
|
||||
|
||||
if ((p = strchr(alpha, ch)) == NULL)
|
||||
continue;
|
||||
|
||||
idx = (p - alpha) % 26;
|
||||
|
||||
total += !wasused[idx];
|
||||
wasused[idx] = 1;
|
||||
if (total == 26)
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
const char *tests[] = {
|
||||
"The quick brown fox jumps over the lazy dog.",
|
||||
"The qu1ck brown fox jumps over the lazy d0g."
|
||||
};
|
||||
|
||||
for (i = 0; i < 2; i++)
|
||||
printf("\"%s\" is %sa pangram\n",
|
||||
tests[i], is_pangram(tests[i])?"":"not ");
|
||||
return 0;
|
||||
}
|
||||
23
Task/Pangram-checker/C/pangram-checker-2.c
Normal file
23
Task/Pangram-checker/C/pangram-checker-2.c
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int pangram(const char *s)
|
||||
{
|
||||
int c, mask = (1 << 26) - 1;
|
||||
while ((c = (*s++)) != '\0') /* 0x20 converts lowercase to upper */
|
||||
if ((c &= ~0x20) <= 'Z' && c >= 'A')
|
||||
mask &= ~(1 << (c - 'A'));
|
||||
|
||||
return !mask;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int i;
|
||||
const char *s[] = { "The quick brown fox jumps over lazy dogs.",
|
||||
"The five boxing wizards dump quickly.", };
|
||||
|
||||
for (i = 0; i < 2; i++)
|
||||
printf("%s: %s\n", pangram(s[i]) ? "yes" : "no ", s[i]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue