UVA – 494 – Kinder Garten Game

  • ID : UVA – 494 – Kinder Garten Game
  • Submissions : Java – Accepted
  • Difficulty : Easy
  • Type : Simple Math, Plaindromes
  • Time for Submission : 15 minutes
  • Solution Description :
    • carry a flag and enable it whenever you find a letter and close it whenever you find a non-letter
  • Problems :
    • No Problems, it went smoothly 🙂
  • Code :

import java.util.Scanner;

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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: