Popis problému
Celý popis zadania sa nacháza – Hackerrank.
Riešenie
Skontrolovať, či vstup obsahuje 26 rôznych znakov.
Vytvoril som riešenie v týchto programovacích jazykoch:
Všetky riešenia sú dostupné aj na mojom GitHub profile.
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
import java.util.HashSet; import java.util.Scanner; import java.util.Set; public class Pangrams { public static void main(String[] args) { Scanner stdin = new Scanner(System.in); String string = stdin.nextLine().toLowerCase(); Set<Character> alphabet = new HashSet<>(); for(int i = 0; i < string.length(); i++) { if(string.charAt(i) != ' ') { alphabet.add(string.charAt(i)); } } if(alphabet.size() == 26) { System.out.println("pangram"); } else { System.out.println("not pangram"); } stdin.close(); } } |
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
function processData(input) { var hash = {}; input = input.toLowerCase().replace(/\s+/g, ''); for(var i = 0; i < input.length; i++) { hash[input[i]] = true; } if(isPangram(hash)) { console.log("pangram"); } else { console.log("not pangram"); } } function isPangram(hash) { var chars = 0; for(prop in hash) { if(hash.hasOwnProperty(prop)) { chars++; } } return chars === 26; } process.stdin.resume(); process.stdin.setEncoding("ascii"); _input = ""; process.stdin.on("data", function (input) { _input += input; }); process.stdin.on("end", function () { processData(_input); }); |
Ruby
1 2 3 4 5 6 7 8 |
require 'set' s = Set.new(gets.downcase.gsub(/\s+/, "").chars()) if(s.size() == 26) puts "pangram" else puts "not pangram" end |
Scala
1 2 3 4 5 6 7 8 9 10 |
import scala.io.Source object Pangrams extends App { println( if(Source.stdin.bufferedReader().readLine().toLowerCase().distinct.replaceAll("\\s+", "").distinct.length == 26) "pangram" else "not pangram" ) } |