Competitive Programming Solutions

GitHub
back to dashboard

P. Count Words

Codeforces - Sheet #4 (Strings) · limit: 1s · memory: 256MB · view on codeforces

input

Meep Meep!

output

2
Main.java
static void solve() {

        // Write your solution here
        String S = in.nextLine();
        int wordsCounter = 0;
        String[] words = S.trim().split("[\\s!,.?]+");
        for (String word : words) {
            if (!word.isEmpty())
                wordsCounter++;

        }
        out.println(wordsCounter);
    }