# Afjörmun

## Question

{% embed url="<https://open.kattis.com/problems/afjormun>" %}

## Solution

### Idea

I believe the tricky part for this question is to deal with the input in C. The main algorithm is not that hard. It is just you upper the first letter and iterate all the way till the end, if it `isupper()`, then turn it to lower letter. Otherwise, just leave it as it is.

### Code

{% @github-files/github-code-block url="<https://github.com/mendax1234/Coding-Problems/blob/main/kattis/afjormun/afjormun.c>" %}

## Take-away

### Read a line in C

To read a line in C, it is "safer" to use `fgets()`. See more about it in [Broken mention](broken://spaces/KipySCGxC8NC1UpA24DS/pages/HaKcbj6IX3CgvoZguHKH#fgets).

{% code lineNumbers="true" %}

```c
char line[MAX_LEN];

if (fgets(line, MAX_LEN, stdin))
{
  line[strcspn(line, "\n")] = 0;
}
```

{% endcode %}

`MAX_LEN` should be the actual length of the string +1 because `fgets()` may read the `\n` character!

{% hint style="info" %}
Note that sometimes this method is not 100% safe. So, the safest way I recommend is to use cs1010 library.
{% endhint %}

### Read an integer with newline

Suppose we input **an** integer with `\n`, to read it into a variable using `scanf()`, use the code below:

{% code lineNumbers="true" %}

```c
int a;
scanf("%d", &a);
```

{% endcode %}

### Read several integers with newline

This will be a bit tricky. For the first integer, we can still use the method above [#read-an-integer-with-newline](#read-an-integer-with-newline "mention"). But for the remaining integers, we should use the following method to read:

{% code lineNumbers="true" %}

```c
scanf("\n%d", &a);
```

{% endcode %}

The leading `\n` is used to consume the `\n` that is left in the `stdin`.


---

# 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://wenbo-notes.gitbook.io/coding/kattis/easy/afjormun.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.
