码迷,mamicode.com
首页 > 其他好文 > 详细

URAL - 1786 Sandro's Biography

时间:2015-04-20 09:28:24      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:

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

 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

标签:

原文地址:http://blog.csdn.net/qq_18738333/article/details/45141983

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!