#!/usr/bin/env python import re n = 5 with open("./input_file.txt", "r") as f: s = f.read() l = re.findall(r'\w+',s) print repr([x for x in l if l.count(x) == n])
#!/usr/bin/perl open FH, "<input_file.txt"; local $/; $str = <FH>; $n = 5; %h = (); $h{$1}++ while $str =~ /(\w+)/g; print '['.(join ", ", grep {$h{$_} == 5} keys %h).']';
#!/usr/bin/env python import re n = 5 with open("./input_file.txt", "r") as f: s = f.read() d={} for x in re.findall(r'\w+',s): if x in d: d[x] += 1 else: d[x] = 1 print repr([k for k,v in d.items() if v == n])
#!/usr/bin/perl open FH, "<./input_file.txt"; local $/; $str = <FH>; $n = 5; chomp($str); foreach(split(/ /, $str)){$h{$_}++;} my $res ="["; foreach(keys(%h)) {if($h{$_} == $n){$res .= "$_, ";}} $res .= "]"; print $res;
import Data.List import Data.Char main = interact -- IO $ unlines -- combine meta-data into string . map (\(n, w) -> if (n == 5) then show w else "") . sort -- sort meta-data by occurances . map (\s -> (length s, head s)) -- transform to sublist meta-data . group -- break into sublists of unique words . sort -- sort words . words -- break into words . map (\c -> -- simplify chars in input if isAlpha c then toLower c else ' ')
#include <stdlib.h> #include <stdio.h> #include <errno.h> #include <string> #include <iostream> #include <set> std::multiset<std::string> words; void prepare() { char *p = 0; int err = 1; while ( 1 == scanf("%as", &p)) { words.insert(p); free(p); } if (errno) { perror("scanf"); abort(); } } void output(int n) { std::multiset<std::string>::iterator it(words.begin()); std::string out; for(;it!=words.end(); it = words.upper_bound(*it)) { if ( words.count(*it) == n ) out.append(" ," + *it); } if (out.find(" ,") == 0 ) out.erase(0, 2); std::cout<<"["<<out<<"]\n"; } int main(int argc, char **argv) { prepare(); output(atoi(argv[1])); return 0; }
Source: https://habr.com/ru/post/163467/