1786. Sandro's Biography
Time limit: 1.0 second
Memory limit: 64 MB
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
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”.
Problem Author: Olga Soboleva
Problem Source: Ural Regional School Programming Contest 2010 |
使用朴素的查找即可;
#include<iostream>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<stack>
#include<queue>
#include<iomanip>
#include<map>
#include<set>
#define pi 3.14159265358979323846
using namespace std;
char s[210];
int main()
{
scanf("%s",&s);
int len=strlen(s);
int cnt,ans=1000;
for(int i=0;i<=len-6;++i)
{
cnt=0;
if(s[i]!='S')
{
if(s[i]=='s'||(s[i]>='A'&&s[i]<='Z'))
++cnt;
else
cnt+=2;
}
if(s[i+1]!='a')
{
if(s[i+1]=='A'||(s[i+1]>='a'&&s[i+1]<='z'))
++cnt;
else
cnt+=2;
}
if(s[i+2]!='n')
{
if(s[i+2]=='N'||(s[i+2]>='a'&&s[i+2]<='z'))
++cnt;
else
cnt+=2;
}
if(s[i+3]!='d')
{
if(s[i+3]=='D'||(s[i+3]>='a'&&s[i+3]<='z'))
++cnt;
else
cnt+=2;
}
if(s[i+4]!='r')
{
if(s[i+4]=='R'||(s[i+4]>='a'&&s[i+4]<='z'))
++cnt;
else
cnt+=2;
}
if(s[i+5]!='o')
{
if(s[i+5]=='O'||(s[i+5]>='a'&&s[i+5]<='z'))
++cnt;
else
cnt+=2;
}
ans=min(ans,cnt);
}
int zans=5*ans;
printf("%d\n",zans);
return 0;
}