Problem Statement
A description of the problem can be found on Hackerrank.
Solution
Check if every line in lowercase matches this regex pattern:
.*hackerrank.*
I created solution in:
All solutions are also available on my GitHub.
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
import java.util.*; public class HackerrankTweets { public static void main(String[] args) { Scanner stdin = new Scanner(System.in); int tests = Integer.parseInt(stdin.nextLine()); int count = 0; for(int i = 0; i < tests; i++) { if(stdin.nextLine().toLowerCase().matches(".*hackerrank.*")) { count++; } } System.out.println(count); stdin.close(); } } |
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
'use strict'; const processData = input => { let lines = input.split('\n').slice(1); let matches = lines.filter(line => line.toLowerCase().match(/.*hackerrank.*/)); console.log(matches.length); }; process.stdin.resume(); process.stdin.setEncoding("ascii"); var _input = ""; process.stdin.on("data", input => _input += input); process.stdin.on("end", () => processData(_input)); |
Scala
1 2 3 4 5 6 7 |
import scala.io.Source object HackerrankTweets extends App { val lines = Source.stdin.getLines().drop(1) val matchingLines = lines.count(_.toLowerCase.matches(".*hackerrank.*")) println(matchingLines) } |
Ruby
1 2 3 4 5 6 7 8 9 10 |
tests = gets.chomp.to_i result = 0 tests.times do words = gets.chomp.split words.each do |word| result += 1 if word.downcase =~ /.*hackerrank.*/ end end puts result |