# Count the smiley faces!

## [Count the smiley faces!](https://www.codewars.com/kata/583203e6eb35d7980400002a)

Given an array (arr) as an argument complete the function `countSmileys` that should return the total number of smiling faces.

Rules for a smiling face:

* Each smiley face must contain a valid pair of eyes. Eyes can be marked as `:` or `;`
* A smiley face can have a nose but it does not have to. Valid characters for a nose are `-` or `~`
* Every smiling face must have a smiling mouth that should be marked with either `)` or `D`

No additional characters are allowed except for those mentioned.

**Valid smiley face examples:** `:) :D ;-D :~)`\
**Invalid smiley faces:** `;( :> :} :]`

## Example

```
countSmileys([':)', ';(', ';}', ':-D']);       // should return 2;
countSmileys([';D', ':-(', ':-)', ';~)']);     // should return 3;
countSmileys([';]', ':[', ';*', ':$', ';-D']); // should return 1;
```

## Note

In case of an empty array return 0. You will not be tested with invalid input (input will always be an array). Order of the face (eyes, nose, mouth) elements will always be the same.

## Solutions

### 🧠 C++

```cpp
#include <regex>
#include <stdint.h>
int countSmileys(std::vector<std::string> arr)
{
  if(!arr.size())
    return 0;

  uint8_t counter = 0;
  std::regex smile("[:;][-~]?[\\)D]");

  for(auto str : arr)
    if(regex_match(str,smile)) ++counter;

  return counter;
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://anton-veselskyi.gitbook.io/codding-problems-solutions/codewars/6-kyu/count-the-smiley-faces.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
