> For the complete documentation index, see [llms.txt](https://wenbo-notes.gitbook.io/cs1010-notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wenbo-notes.gitbook.io/cs1010-notes/current-year-exam/pe1-ay24-25.md).

# PE1 (AY24/25)

## Problems

### 3. Markup

This question utilizes the function [PE2 Review](/cs1010-notes/past-year-exam/pe2-review.md#is_match), where the `i` position variable is crucial! After knowing this function, I rewrite my solution as follows

{% code lineNumbers="true" %}

```c
void markup(char *line)
{
  long line_len = (long)strlen(line);
  long times = 0;
  for (long i = 0; i < line_len; i += 1)
  {
    if (times >= 1)
    {
      if (is_match(line, (size_t)i, START))
      {
        i += 3-1;
        times += 1;
      }
      else if (is_match(line, (size_t)i, END))
      {
        i += 4-1;
        times = 0;
      }
      else if (is_lower(line[i]))
      {
        putchar(to_upper(line[i]));
      }
      else
      {
        putchar(line[i]);
      }
      continue;
    }
    if (is_match(line, (size_t)i , START))
    {
      i += 3-1;
      times += 1;
    }
    else if (is_match(line, (size_t)i, END))
    {
      i += 4-1;
      times = 0;
    }
    else
    {
      putchar(line[i]);
    }
  }
}
```

{% endcode %}

The idea is to set a variable `times` indicating we have encountered an open `<U>` and we should start printing the upper case letters. And once we encounter a closing `</U>`, we set our times to be 0. And notice that the awesome point of the position `i` is that we deal with **one character at a time!**
