# 1272 - Mensagem Oculta

## Descrição

{% embed url="<https://www.urionlinejudge.com.br/judge/pt/problems/view/1272>" %}

## Solução

Este problema consiste em você separar a entrada por palavras e pegar a primeira letra de cada palavra. Se você tem o recurso de separar por palavras, apenas certifique-se de que suas palavras têm um caractere ou mais. Se você não tem esse recurso, você pode percorrer a frase com um booleano para te indicar se você já pegou a primeira letra de alguma palavra ou não.

{% tabs %}
{% tab title="C99" %}

```c
#include <string.h>
#include <stdio.h>

int main(){
    int N, p, primeiraLetra;
    char frase[51], resposta[51];

    scanf("%d\n", &N);

    for(int i = 0; i < N; ++i){
        gets(frase);

        p = 0;
        primeiraLetra = 1;
        memset(resposta, '\0', sizeof(resposta));

        for(int j = 0; j < strlen(frase); ++j){
            if(primeiraLetra && frase[j] != ' '){
                resposta[p++] = frase[j];
                primeiraLetra = 0;
            }else if(!primeiraLetra && frase[j] == ' '){
                primeiraLetra = 1;
            }
        }

        printf("%s\n", resposta);
    }

    return 0;
}
```

{% endtab %}

{% tab title="C++17" %}

```cpp
#include <iostream>

using namespace std;

int main(){
    int N;
    bool primeiraLetra;
    string frase, resposta;

    cin >> N;
    cin.ignore();

    for(int i = 0; i < N; ++i){
        getline(cin, frase);

        resposta = "";
        primeiraLetra = true;

        for(int j = 0; j < frase.length(); ++j){
            if(primeiraLetra && frase[j] != ' '){
                resposta += frase[j];
                primeiraLetra = false;
            }else if(!primeiraLetra && frase[j] == ' '){
                primeiraLetra = true;
            }
        }

        cout << resposta << endl;
    }

    return 0;
}
```

{% endtab %}

{% tab title="JavaScript 12.18" %}

```javascript
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.split('\n');

let N = parseInt(lines.shift());

for(let i = 0; i < N; ++i){
    let frase = lines.shift().trim().split(' ');

    let resposta = frase.map((x) => x[0]).join('');

    console.log(resposta);
}
```

{% endtab %}

{% tab title="Python 3.9" %}

```python
N = int(input())

for _ in range(N):
    frase = input().strip()

    resposta = ''.join([x[0] if len(x) > 0 else '' for x in frase.split(' ')])

    print(resposta)
```

{% endtab %}
{% endtabs %}


---

# 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://xtecna.gitbook.io/solucoes-da-beecrowd/strings/1272-mensagem-oculta.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.
