First, solve the problem. Then, write the code. ” - John Johnson

It's not at all important to get it right the first time. It's vitally important to get it right the last time. ” - Andrew Hunt and David Thomas

Wednesday, July 16, 2014

Kindergarten Counting Game.

Author : Jisan
Programming language : Java
Difficulty : Easy
Status : Accepted
Problem number : UVA-494
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=435

Code:

import java.util.Scanner;
public class Uva__494 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            String s = in.nextLine();
            boolean jisan = false;
            int count = 0;
            for (char c : s.toCharArray()) {
                if (Character.isLetter(c)) {
                    if (!jisan) {
                        jisan = true;
                        count++;
                    }
                } else{
                    jisan = false;
            }
          }
            System.out.println(count);
        }
    }
}

No comments:

Post a Comment