#include 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; } using System; namespace PangrammChecker { public class PangrammChecker { public static bool IsPangram(string str) { bool[] isUsed = new bool[26]; int ai = (int)'a'; int total = 0; for (CharEnumerator en = str.ToLower().GetEnumerator(); en.MoveNext(); ) { int d = (int)en.Current - ai; if (d >= 0 && d < 26) if (!isUsed[d]) { isUsed[d] = true; total++; } } return (total == 26); } } class Program { static void Main(string[] args) { string str1 = "The quick brown fox jumps over the lazy dog."; string str2 = "The qu1ck brown fox jumps over the lazy d0g."; Console.WriteLine("{0} is {1}a pangram", str1, PangrammChecker.IsPangram(str1)?"":"not "); Console.WriteLine("{0} is {1}a pangram", str2, PangrammChecker.IsPangram(str2)?"":"not "); Console.WriteLine("Press Return to exit"); Console.ReadLine(); } } } #include #include #include #include const std::string alphabet("abcdefghijklmnopqrstuvwxyz"); bool is_pangram(std::string s) { std::transform(s.begin(), s.end(), s.begin(), ::tolower); std::sort(s.begin(), s.end()); return std::includes(s.begin(), s.end(), alphabet.begin(), alphabet.end()); } int main() { const auto examples = {"The quick brown fox jumps over the lazy dog", "The quick white cat jumps over the lazy dog"}; std::cout.setf(std::ios::boolalpha); for (auto& text : examples) { std::cout << "Is \"" << text << "\" a pangram? - " << is_pangram(text) << std::endl; } } package main import "fmt" func main() { for _, s := range []string{ "The quick brown fox jumps over the lazy dog.", `Watch "Jeopardy!", Alex Trebek's fun TV quiz game.`, "Not a pangram.", } { if pangram(s) { fmt.Println("Yes:", s) } else { fmt.Println("No: ", s) } } } func pangram(s string) bool { var missing uint32 = (1 << 26) - 1 for _, c := range s { var index uint32 if 'a' <= c && c <= 'z' { index = uint32(c - 'a') } else if 'A' <= c && c <= 'Z' { index = uint32(c - 'A') } else { continue } missing &^= 1 << index if missing == 0 { return true } } return false } public class Pangram { public static boolean isPangram(String test){ for (char a = 'A'; a <= 'Z'; a++) if ((test.indexOf(a) < 0) && (test.indexOf((char)(a + 32)) < 0)) return false; return true; } public static void main(String[] args){ System.out.println(isPangram("the quick brown fox jumps over the lazy dog"));//true System.out.println(isPangram("the quick brown fox jumped over the lazy dog"));//false, no s System.out.println(isPangram("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));//true System.out.println(isPangram("ABCDEFGHIJKLMNOPQSTUVWXYZ"));//false, no r System.out.println(isPangram("ABCDEFGHIJKL.NOPQRSTUVWXYZ"));//false, no m System.out.println(isPangram("ABC.D.E.FGHI*J/KL-M+NO*PQ R\nSTUVWXYZ"));//true System.out.println(isPangram(""));//false } } function isPangram(s) { var letters = "zqxjkvbpygfwmucldrhsnioate" // sorted by frequency ascending (http://en.wikipedia.org/wiki/Letter_frequency) s = s.toLowerCase().replace(/[^a-z]/g,'') for (var i = 0; i < 26; i++) if (s.indexOf(letters[i]) < 0) return false return true } console.log(isPangram("is this a pangram")) // false console.log(isPangram("The quick brown fox jumps over the lazy dog")) // true function isPangram($text) { foreach (str_split($text) as $c) { if ($c >= 'a' && $c <= 'z') $bitset |= (1 << (ord($c) - ord('a'))); else if ($c >= 'A' && $c <= 'Z') $bitset |= (1 << (ord($c) - ord('A'))); } return $bitset == 0x3ffffff; } $test = array( "the quick brown fox jumps over the lazy dog", "the quick brown fox jumped over the lazy dog", "ABCDEFGHIJKLMNOPQSTUVWXYZ", "ABCDEFGHIJKL.NOPQRSTUVWXYZ", "ABC.D.E.FGHI*J/KL-M+NO*PQ R\nSTUVWXYZ" ); foreach ($test as $str) echo "$str : ", isPangram($str) ? 'T' : 'F', '
'; def pangram?(sentence) unused_letters = ('a'..'z').to_a - sentence.downcase.chars.to_a unused_letters.empty? end p pangram?('this is a sentence') # ==> false p pangram?('The quick brown fox jumps over the lazy dog.') # ==> true #![feature(test)] extern crate test; use std::collections::HashSet; pub fn is_pangram_via_bitmask(s: &str) -> bool { // Create a mask of set bits and convert to false as we find characters. let mut mask = (1 << 26) - 1; for chr in s.chars() { let val = chr as u32 & !0x20; /* 0x20 converts lowercase to upper */ if val <= 'Z' as u32 && val >= 'A' as u32 { mask = mask & !(1 << (val - 'A' as u32)); } } mask == 0 } pub fn is_pangram_via_hashset(s: &str) -> bool { // Insert lowercase letters into a HashSet, then check if we have at least 26. let letters = s.chars() .flat_map(|chr| chr.to_lowercase()) .filter(|&chr| chr >= 'a' && chr <= 'z') .fold(HashSet::new(), |mut letters, chr| { letters.insert(chr); letters }); letters.len() == 26 } pub fn is_pangram_via_sort(s: &str) -> bool { // Copy chars into a vector, convert to lowercase, sort, and remove duplicates. let mut chars: Vec = s.chars() .flat_map(|chr| chr.to_lowercase()) .filter(|&chr| chr >= 'a' && chr <= 'z') .collect(); chars.sort(); chars.dedup(); chars.len() == 26 } fn main() { let examples = ["The quick brown fox jumps over the lazy dog", "The quick white cat jumps over the lazy dog"]; for &text in examples.iter() { let is_pangram_sort = is_pangram_via_sort(text); println!("Is \"{}\" a pangram via sort? - {}", text, is_pangram_sort); let is_pangram_bitmask = is_pangram_via_bitmask(text); println!("Is \"{}\" a pangram via bitmask? - {}", text, is_pangram_bitmask); let is_pangram_hashset = is_pangram_via_hashset(text); println!("Is \"{}\" a pangram via bitmask? - {}", text, is_pangram_hashset); } }