您的位置:首页 > 其它

URAL 1786 Sandro's Biography

2015-04-27 23:27 507 查看
题意:给你一段字符串,只有大小写字母。魔法师可以改变字符,将一个字母改成另一外一个大小写相同的字母需要花费5,大小写转换也需要花费5,问在文本中如何花费最小让文本中出现’Sandro’这个单词。

解法:数据很小。字符串长度最长200,直接暴力一波就可以了,扫一遍。

#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
char s[220];
while(~scanf("%s",s))
{
int len = strlen(s);
int ans = 12;
for(int i = 0; i < len - 5; i++)
{
int x = 0;
if(s[i] != 'S')
{
if(s[i] == 's') x++;
else if(isupper(s[i])) x++;
else x += 2;
}
if(s[i+1] != 'a')
{
if(s[i+1] == 'A') x++;
else if(islower(s[i+1])) x++;
else x += 2;
}
if(s[i+2] != 'n')
{
if(s[i+2] == 'N') x++;
else if(islower(s[i+2])) x++;
else x += 2;
}
if(s[i+3] != 'd')
{
if(s[i+3] == 'D') x++;
else if(islower(s[i+3])) x++;
else x += 2;
}
if(s[i+4] != 'r')
{
if(s[i+4] == 'R') x++;
else if(islower(s[i+4])) x++;
else x += 2;
}
if(s[i+5] != 'o')
{
if(s[i+5] == 'O') x++;
else if(islower(s[i+5])) x++;
else x += 2;
}
ans = min(ans,x);
}
printf("%d\n",ans * 5);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  暴力 水题