入力 The quick brown fox jumps over a lazy dog. The jay, pig, fox, zebra and my wolves quack! Pack my box with seven dozen liquor jugs. The horse, pig, fox, zebra and my wolves quack! Jackdaws love my small sphinx of quartz. Jackdaws love my big sphinx of quartz. The quick brown fox jumps over a lazy cat. Pack my box with five dozen liquor jugs.
出力 Jackdaws love my big sphinx of quartz. 0004デフォルトの名無しさん2023/08/06(日) 17:47:37.64ID:RhhSFLLO>>3 Kotlin https://paiza.io/projects/cmJpXwaAhFH6jYozb0bb2g0005デフォルトの名無しさん2023/08/06(日) 18:08:09.04ID:RhhSFLLO>>3 C https://paiza.io/projects/McLPuKlM4c-1C9EgarDGjw0006デフォルトの名無しさん2023/08/06(日) 19:07:03.27ID:Md+pNxjw use std::io::{self, BufRead, BufReader}; const FULL_BITS: u32 = (1 << 26) - 1; fn main() { let mut shortest: Option<String> = None; for line in BufReader::new(io::stdin()).lines() { let line = line.unwrap(); let mut bits = 0; for b in line.as_bytes() { let index = match b { b'A'..=b'Z' => b - b'A', b'a'..=b'z' => b - b'a', _ => continue, }; bits |= 1 << index; } if bits != FULL_BITS { continue; } if let Some(ref shortest) = shortest { if shortest.len() < line.len() { continue; } } shortest = Some(line); } if let Some(shortest) = shortest { println!("{shortest}"); } else { eprintln!("ERROR: no matched lines"); } } 0007デフォルトの名無しさん2023/08/06(日) 20:04:54.35ID:pJXl8PQk>>3 R https://ideone.com/ZdKsPa0008デフォルトの名無しさん2023/08/07(月) 01:25:47.55ID:dolrRGoi>>6 それなんて言語? 000992023/08/07(月) 01:46:18.23ID:PMO8D1QO>>3 Perl5
for (<DATA>) { my %h = map{$_ => 1} grep{/[a-z]/i} split ''; push @a, $_ if 26 == keys %h; } @s = sort{length($a) <=> length($b)} @a; print $s[0]; __DATA__ The quick brown fox jumps over a lazy dog. The jay, pig, fox, zebra and my wolves quack! Pack my box with seven dozen liquor jugs. The horse, pig, fox, zebra and my wolves quack! Jackdaws love my small sphinx of quartz. Jackdaws love my big sphinx of quartz. The quick brown fox jumps over a lazy cat. Pack my box with five dozen liquor jugs.
※ 見易くするためインデントを全角スペースに置換してあります。
実行結果:
$ perl 22_3_az26.pl Jackdaws love my big sphinx of quartz. 0010デフォルトの名無しさん2023/08/07(月) 01:57:03.56ID:PMO8D1QO>>9 ゴメン、2行目に間違いあり…orz
my %h = map{$_ => 1} grep{/[a-z]/i} split ''; ↓正しくは my %h = map{$_ => 1} map{lc} grep{/[a-z]/i} split '';
>>3 Perl5 use List::Util 'first'; for (<DATA>) { my %h = map{lc $_ => 1} /([A-Za-z])/g; $a[length $_] = $_ if 26 == keys %h; } print first{defined} @a; __DATA__ The quick brown fox jumps over a lazy dog. The jay, pig, fox, zebra and my wolves quack! Pack my box with seven dozen liquor jugs. The horse, pig, fox, zebra and my wolves quack! Jackdaws love my small sphinx of quartz. Jackdaws love my big sphinx of quartz. The quick brown fox jumps over a lazy cat. Pack my box with five dozen liquor jugs.
実行結果 ~ $ perl 22_3_az26_a.pl Jackdaws love my big sphinx of quartz. 0027デフォルトの名無しさん2023/08/11(金) 02:52:08.14ID:45O+1i6X そう、haskellの評価戦略はcall by need (の一種) で必要に応じて展開される、head . sort では 「sortした後の最初の項」を求めているのでそれを出すための必要最小限の事しかしない