> 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!**


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://wenbo-notes.gitbook.io/cs1010-notes/current-year-exam/pe1-ay24-25.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.
