ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 2023. Дональд-почтальон

AC_Sol in c++
Послано Adkham 7 ноя 2017 23:33
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string box1[3][3] = {    "Alice", "Ariel","Aurora",
                            "Phil", "Peter", "Olaf",
                            "Phoebus", "Ralph", "Robin"
                        };
    string box2[3][3] = {    "Bambi", "Belle", "Bolt",
                            "Mulan", "Mowgli", "Mickey",
                            "Silver", "Simba", "Stitch"
                        };
    string box3[3][3] = {    "Dumbo", "Genie", "Jiminy",
                            "Kuzko", "Kida", "Kenai",
                            "Tarzan", "Tiana", "Winnie"
                        };
    int n, step;
    string names;
    bool here1, here2, here3;
     here2 = here3 = false;
     here1 = true;
    step = 0;
    cin >> n;
    for (int m = 0; m < n; m++)
    {
        cin >> names;
        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                if (box1[i][j] == names)
                {
                    here1 = true;
                    if (here2)
                    {
                        step++;
                    }
                    else
                        if (here3)
                        {
                            step = step + 2;
                        }
                    here2 = false;
                    here3 = false;
                    break;
                }
            }
        }
        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                if (box2[i][j] == names)
                {
                    here2 = true;
                    if (here1)
                    {
                        step++;
                    }
                    else
                        if (here3)
                        {
                            step++;
                        }
                    here1 = false;
                    here3 = false;
                    break;
                }
            }
        }
        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                if (box3[i][j] == names)
                {
                    here3 = true;
                    if (here2)
                    {
                        step++;
                    }
                    else
                        if (here1)
                        {
                            step = step + 2;
                        }
                    here1 = false;
                    here2 = false;
                    break;
                }
            }
        }
    }
    cout << step << endl;
    return 0;
}
Re: AC_Sol in c++
Послано malegkin 22 авг 2018 15:58
#include <iostream>
#include <string>
#include <cmath>


int32_t get_post_case_offset(const std::string& receiver)
{
    uint32_t out = 0;
    switch (receiver[0]){
        case 'A':
        case 'P':
        case 'O':
        case 'R':
            out = 0;
            break;

        case 'B':
        case 'M':
        case 'S':
            out = 1;
            break;

        default:
            out = 2;
    }

    return out;
}

std::string get_receiver(){
    std::string out;
    std::cin >> out;
    return std::move(out);
}

int main()
{
    uint32_t n;
    std::cin >> n;

    uint32_t steps = 0;
    int32_t last_offset = 0;

    for (;n;n--){
        int32_t offset = get_post_case_offset(get_receiver());
        steps += abs(last_offset - offset);
        last_offset = offset;
    }

    std::cout << steps << std::endl;

   return 0;
}