UK and US: Part 2

Sort by

recency

|

89 Discussions

|

  • + 0 comments
    import re
    
    
    txt = ""
    for i in range(int(input())):
        txt +=" "+input()
    
    
    for j in range(int(input())):
        
        word = input()
        i = word.index("our")
        w1,w2  = word[:i+1],word[i+2:]
        
        print(len(re.findall(fr'\b{w1}u?{w2}\b',txt)))
    
  • + 0 comments

    Java 15:

    import java.io.*;
    import java.util.*;
    import java.util.regex.Pattern;
    import java.util.regex.Matcher;
    public class Solution {
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            int n = Integer.parseInt(scanner.nextLine());
            
            //Merge all input together
            String input="";
            for(int i=0;i<n;i++)
                input=input+scanner.nextLine()+" ";
            
            int t = Integer.parseInt(scanner.nextLine());
            for(int i=0;i<t;i++)
            {   String uk_word = scanner.nextLine();
                String us_word = uk_word.replaceAll("our","or");
                String regex = String.format("\\b(%s|%s)\\b",uk_word,us_word);
                Pattern pattern = Pattern.compile(regex);
                Matcher matcher = pattern.matcher(input);
                int count=0;
                while(matcher.find())   count++;
                System.out.println(count);
            }
        }
    }
    
  • + 0 comments

    Javascript:

    const lines = input.split(/^\d+\s*$/gm);
    const words = lines[2].trim().split("\n");
    words.forEach((word) => {
       const regex = new RegExp(`\\b(${word}|${word.replace('our', 'or')})\\b`, 'gm');
       const total = lines[1].match(regex);
    
       console.log(total?.length || 0);
    })
    
  • + 0 comments
    import re
    
    content = ''
    for _ in range(int(input())):
        content += input() + ' '
        
    for _ in range(int(input())):
        uk = input()
        us = uk.replace('our', 'or')
        pattern = f'\\b({uk}|{us})\\b'
        print(len(re.findall(pattern, content)))
    
  • + 0 comments
    s = " ".join([input() for _ in range(int(input()))]).split()
    
    for _ in range(int(input())):
        i = input()
        print(s.count(i) + s.count(i.replace("our", "or")))