URAL - 1786 Sandro's Biography

Sandro‘s Biography

Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u

Submit Status

Description

Leogius was searching in a library for a book recommended to him by the teacher of theoretical magic. Suddenly he found an ancient chronicle written on several sheets of parchment. Having looked through it, Leogius understood
that it described the life and amazing adventures of a lich. Could it be the biography of Lich Sandro that had been lost many centuries ago? If so, the manuscript had to be shown to the Supreme Council of Magicians as soon as possible. But there was one problem:
the text contained no mention of the name Sandro. What could be done? The Council might not believe that the chronicle recounted Sandro‘s life.

Leogius decided to correct the manuscript. He found a magician who was willing to do it. But a good job had to be paid well. The proofreader agreed to replace any letter by any other same-case letter (an uppercase letter by an
uppercase letter and a lowercase letter by a lowercase letter) for five gold coins. He also could change the case of any letter for five gold coins. Help Leogius determine the minimal quantity of gold coins he had to pay to make the string “Sandro” appear
in the text.

Input

The only line contains the text of the manuscript. It consists of lowercase and uppercase English letters. The number of letters in the text is at least six and at most 200.

Output

Output the minimal quantity of gold coins that must be paid to make the name Sandro appear in the text.

Sample Input

input output
MyNameIsAlexander
20

Notes

In the example the corrector will have to perform four operations after which the line will sequentially take the following form: “MyNameIsAlesander”, “MyNameIsAlesandrr”, “MyNameIsAlesandro”, and “MyNameIsAleSandro”.

枚举就好了。

#include<iostream>
#include<algorithm>
#include<cctype>
using namespace std;
int cost1(char c)
{
	if (c == 'S') return 0;
	if (c == 's'||isupper(c)) return 5;
	return 10;
}
int cost2(char c)
{
	if (c == 'a') return 0;
	if (c == 'A'||islower(c)) return 5;
	return 10;
}
int cost3(char c)
{
	if (c == 'n') return 0;
	if (c == 'N'||islower(c)) return 5;
	return 10;
}
int cost4(char c)
{
	if (c == 'd') return 0;
	if (c == 'D'||islower(c)) return 5;
	return 10;
}
int cost5(char c)
{
	if (c == 'r') return 0;
	if (c == 'R'||islower(c)) return 5;
	return 10;
}
int cost6(char c)
{
	if (c == 'o') return 0;
	if (c == 'O'||islower(c)) return 5;
	return 10;
}

int main()
{
	char s[205];
	while (cin >> s)
	{
		int len = strlen(s);
		int ans = 60;
		int temp;
		for (int i = 0; i < len - 5; i++)
		{
			temp = cost1(s[i]) + cost2(s[i + 1]) + cost3(s[i + 2]) + cost4(s[i + 3]) + cost5(s[i + 4]) + cost6(s[i + 5]);
			ans = min(ans, temp);
		}
		cout << ans << endl;
	}
}

URAL - 1786 Sandro's Biography

时间: 2024-10-14 11:00:49

URAL - 1786 Sandro's Biography的相关文章

URAL 1723. Sandro&#39;s Book

1723. Sandro's Book Time limit: 0.5 second Memory limit: 64 MB It's been quite a number of years since Lich Sandro retired. Sometimes in the evenings, when he feels especially lonely, he takes a book that was presented to him by his student magicians

Ural 1081 Binary Lexicographic Sequence(DP)

题目地址:Ural 1081 先用dp求出每个长度下的合法序列(开头为1)的个数.然后求前缀和.会发现正好是一个斐波那契数列.然后每次判断是否大于此时长度下的最少个数,若大于,说明这一位肯定是1,若小于,则肯定是0.就这样不断输出出来即可. 代码如下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #in

URAL 1684. Jack&#39;s Last Word KMP

题目来源:URAL 1684. Jack's Last Word 题意:输入a b 把b分成若干段 每一段都是a的前缀 思路:b为主串 然后用a匹配b 记录到b的i位置最大匹配的长度 然后分割 分割的时候要从后往前 如果a = abac b = abab 那么如果从前往后 首先覆盖了aba 然后b就不能覆盖了 从后往前就可以了 首先覆盖ab 下一次还是ab 因为已经记录了到i位置的最大匹配长度 根据长度从末尾倒退 每次倒退的时候只要是最大的匹配的长度 因为如果在某一次的递推 记录的最大匹配的前缀

ural 1272. Non-Yekaterinburg Subway

1272. Non-Yekaterinburg Subway Time limit: 1.0 secondMemory limit: 64 MB A little town started to construct a subway. The peculiarity of the town is that it is located on small islands, some of them are connected with tunnels or bridges. The mayor is

ural 1273. Tie

1273. Tie Time limit: 1.0 secondMemory limit: 64 MB The subway constructors are not angels. The work under the ground and… Well, they are not angels. And where have you seen angels? It is all in a lifetime! Show me first somebody who has never… and t

ural 1269. Obscene Words Filter

1269. Obscene Words Filter Time limit: 0.5 secondMemory limit: 8 MB There is a problem to check messages of web-board visitors for the obscene words. Your elder colleagues commit this problem to you. You are to write a program, which check if there i

ural 1218. Episode N-th: The Jedi Tournament

1218. Episode N-th: The Jedi Tournament Time limit: 1.0 secondMemory limit: 64 MB Decided several Jedi Knights to organize a tournament once. To know, accumulates who the largest amount of Force. Brought each Jedi his lightsaber with him to the tourn

ural 1217. Unlucky Tickets

1217. Unlucky Tickets Time limit: 1.0 secondMemory limit: 64 MB Strange people live in Moscow! Each time in the bus, getting a ticket with a 6-digit number, they try to sum up the first half of digits and the last half of digits. If these two sums ar

ural 1219. Symbolic Sequence

1219. Symbolic Sequence Time limit: 1.0 secondMemory limit: 64 MB Your program is to output a sequence of 1 000 000 lowercase Latin letters. This sequence should satisfy the following restrictions: Every letter occurs not more than 40 000 times in th