The British and American Style of Spelling

Sort by

recency

|

93 Discussions

|

  • + 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 us_word = scanner.nextLine();
                String uk_word = us_word.replaceAll("ze$","se");
                Pattern pattern = Pattern.compile(us_word+"|"+uk_word);
                Matcher matcher = pattern.matcher(input);
                int count=0;
                while(matcher.find())
                    count++;
                System.out.println(count);
            }
        }
    }
    
  • + 0 comments

    for begginers python

    # Enter your c
    import re
    st = ""
    for i in range(int(input())) :
        st += (" "+input())
        
    for t in range(int(input())) :
        c = 0
        word1 = input()
        word2 = word1[:len(word1)-2]+"se"
        c += len(list(re.findall(word1,st)))
        c += len(list(re.findall(word2,st)))
        
        print(c)
        
    
  • + 0 comments

    Javascript solution:

    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(/ze$/, 'se')})\\b`, 'gmi');
        const total = lines[1].match(regex)?.length || 0;
    
        console.log(total);
    });
    
  • + 0 comments

    Fun fact: the -ze spelling is still acceptable in British English, even though much less common, and is actually preferred by the Oxford dictionary

  • + 0 comments

    Is this considered metaprogramming?

    import re
    
    n = int(input())
    text = '\n'.join([input() for _ in range(n)])
       
    t = int(input())
    for _ in range(t):
        word = input()
        word_uk = word.replace('ze', 'se')
        pattern = f'({word}|{word_uk})'
        print(len(re.findall(pattern, text)))