51nod 1182完美字符串
来源:互联网 发布:艾美特 暖风机知乎 编辑:程序博客网 时间:2024/05/17 01:41
Input
输入一个字符串S(S的长度 <= 10000),S中没有除字母外的其他字符。
Output
由你将1-26分配给不同的字母,使得字符串S的完美度最大,输出这个完美度。
Input示例
dad
Output示例
77<pre name="code" class="cpp">#include <iostream>#include <algorithm>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;char s[10005];int b[500];int cmp(int a,int b){return a>b;}int main(){ int sum,len; while(scanf("%s",&s)!=EOF) { sum=0; memset(b,0,sizeof(b)); len=strlen(s); for(int i = 0;i < len ;i++) { if(s[i]>='a'&&s[i]<='z'){ b[s[i]]++; } else if(s[i]>='A'&&s[i]<='Z'){ s[i]=s[i]-27; b[s[i]]++; } } int k = 26; sort(b,b+150,cmp); for(int i = 0; i < 30, k >= 1; ++i, k--) { if(b[i]!=0){ sum=sum+b[i]*k; } } cout<<sum<<endl; } return 0;}
0 0
- 51NOD 1182 完美字符串
- 51nod 1182 完美字符串
- 51 nod 1182 完美字符串
- 51nod 1182 完美字符串
- 51nod 1182完美字符串
- 51nod 1182 完美字符串
- 51Nod 1182 完美字符串
- 【51Nod】1182 完美字符串
- 51nod 1182 完美字符串
- 51Nod 1182 完美字符串
- 51nod 1182 完美字符串
- 51nod-完美字符串
- 51nod 完美字符串
- 51 Nod 完美字符串
- 51Nod-1182-完美字符串
- 【51Nod】1182 - 完美字符串(贪心)
- 51nod 1182 完美字符串【贪心】
- 51nod 1182 完美字符串(贪心)
- js屏蔽错误代码不让游览器显示错误提示
- checkbox 里面的value的作用
- 如何辨别茶叶里有没有添加香精
- web.xml的配置及加载顺序
- PHP获取准确的IP地址的方法
- 51nod 1182完美字符串
- Ubuntu 安装mysql和简单操作
- Jena环境变量配置(可进行Sparql 查询)
- 介绍一下except的用法和作用?
- .net Stream MemoryStream 的使用注意事项 及 把流输出到客户端.
- java枚举类型
- js版本问题
- 介绍一下Python下range()函数的用法?
- 快捷设置mysql字符集utf-8