Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Help Your Friend L!

By SaikatS · Limits 1s, 512 MB

Not only L is an incredibly mysterious detective, but also he is the world's greatest. He worked with organizations all over the world helping to solve crimes and even prevented World War III. Now L is working on the KIRA case. One day when L is busy with some other matter that is involved in the KIRA case and that time Watari gives him a paper that came from KIRA. The paper has a sentence now L is curious why KIRA sent the sentence to L. Then he wants to find out the sentence is a valid sentence or not.

You are a good friend of L. Now L gives you the sentence to find out the sentence is a valid sentence or not.

We can consider a sentence valid if it conforms to the following rules:

  • The sentence must start with a capital letter, followed by a lowercase letter or a space.
  • Word can be started with a capital letter, lowercase letters, separators ( , - : ; ) or terminal marks ( . ? ! ) but all other characters must be lowercase letters, separators ( , - : ; ) or terminal marks ( . ? ! ).
  • There must be a single space between each word.
  • The sentence must end with a terminal mark immediately following a word.


The first line contains an integer T (1 <= T <= 100), number of test case.
Next, each T line contains a string S (1 <= |S| <= 105).
The string contains capital or small English letter ('a'...'z' or 'A' ... 'Z), separators ( , - : ; ) or terminal marks ( . ? ! ).


For each test case you have to print "Yes" if the sentence is valid or "No" (without quotes).


L do you know Gods of Death love apples?
If Kira gets caught, he is evil. If Kira rules the world, he is justice




    32% Solution Ratio

    FAHIM.ctgEarliest, 1M ago

    Sanjida999Fastest, 0.0s

    FAHIM.ctgLightest, 131 kB

    mdvirusShortest, 401B


    Login to submit