a1000's blog

By a1000, history, 21 month(s) ago, In English

Hello there, regarding the problem 58A Chat room (link: https://codeforces.com/problemset/problem/58/A) Test case 5 is "helhcludoo" which is giving me WA and it's wrong according to the problem statement.

My code:-

String s = sc.next(); String regex = ".*(h+)(e+)(l+)(l+)(o+).*"; System.out.println(s.matches(regex)?"YES":"NO");

Am I doing something wrong?

 
 
 
 
  • Vote: I like it
  • -22
  • Vote: I do not like it

»
21 month(s) ago, # |
  Vote: I like it +21 Vote: I do not like it

The problem wants you to check if the given string contains the subsequence $$$hello$$$. Your regex expression does something different.

  • »
    »
    21 month(s) ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    My regex may be wrong but in the test case ""helhcludoo" has the answer as "YES" but I don't see "hello" in there.

    • »
      »
      »
      21 month(s) ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I've underlined it: $$$\underline{hel}hc\underline{l}ud\underline{o}o$$$

      • »
        »
        »
        »
        21 month(s) ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Ah, I see the "hello" isn't supposed to be together. Thanks for helping!