ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1786. Sandro's Biography

#include<iostream>
#include<list>
using namespace std;
bool in_the_range(char a)
{
    if (a >= 'a'&&a <= 'z')
    {
        return true;
    }
    else
    {
        return false;
    }
}

int chance_one_symb(char in_symbol, char out_sybmbol)
{
    if ((in_the_range(in_symbol) && in_the_range(out_sybmbol)) || !(in_the_range(in_symbol)) && !(in_the_range(out_sybmbol)))
    {
        if (in_symbol == out_sybmbol)
        {
            return 0;
        }
        else
        {
            return 5;
        }
    }
    else
    {
        if (((int)in_symbol + 32) == out_sybmbol || ((int)in_symbol - 32) == out_sybmbol)
        {
            return 5;
        }
        else
        {
            return 10;
        }
    }


}

int main()
{
    char str[200] = { NULL };
    const char word[6] = { 'S', 'a', 'n', 'd', 'r', 'o' };
    int final_cost = 60, temp_cost = 0;
    cin.get(str, 200);
    list<char> temp;
    list<char>::iterator ptr;
    for (size_t i = 0; i < 6; i++)
    {
        temp.push_back(str[i]);
    }
    int j = 0;
    for (size_t i = 6; i <= strlen(str); i++)
    {
        for (ptr=temp.begin(); ptr!=temp.end(); ptr++)
        {
            temp_cost += chance_one_symb(*ptr, word[j]);
            if (temp_cost>=final_cost)
            {
                break;
            }
            j++;
        }
        j = 0;
        if (temp_cost < final_cost)
        {
            final_cost = temp_cost;
        }
        temp_cost = 0;
        temp.pop_front();
        temp.push_back(str[i]);


    }
    cout << final_cost;
    return 0;
}

Edited by author 14.07.2016 22:33
Seeing a similar code on other tasks previously, i can already tell the problem by intuition.
Try something like <194 symbols>Sandro.