华为OJ平台试题 —— 字符串:名字的漂亮度
来源:互联网 发布:精通python网络爬虫pdf 编辑:程序博客网 时间:2024/05/22 14:14
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: rgb(255, 255, 255);">1、名字的漂亮度</span>
代码:
<pre name="code" class="cpp">
#include<stdio.h>/* * 对数组a 进行排序 */ void sort(int a[], int n){ int i, j, temp; for( i = 0; i < n; i++) for(j = i; j < n ; j++) { if(a[i] < a[j]) { temp = a[i]; a[i] = a[j]; a[j] = temp; } }}int main(void){int n; /* 名字个数 */ scanf("%d",&n);while(n--){char str[100];int a[26]={0}, /* 名字中每个字符的个数组成的数组 */ i = 0, result = 0; /* 漂亮度µ */ scanf("%s",str); /* 输入名字 */ <img src="http://img.blog.csdn.net/20150815100447310" alt="" />while(str[i] != '\0'){if(str[i] >= 'a' && str[i] <= 'z'){a[str[i]-'a']++;}if(str[i]>='A'&&str[i]<='Z'){a[str[i]-'A']++;}i++;}sort(a,26); /* 排序 *//* 对出现次数最多的字母给予最大的权值即26,其他的依次递减 */ for(i=0;i<=25;i++){result+=(26-i)*a[i];}printf("%d\n",result);}return 0;}
0 0
- 华为OJ平台试题 —— 字符串:名字的漂亮度
- 华为OJ——名字的漂亮度
- 华为OJ——名字的漂亮度
- 华为OJ——名字的漂亮度
- 华为oj-名字的漂亮度
- 华为OJ测试--名字的漂亮度
- 华为OJ 名字的漂亮度
- 华为OJ 名字的漂亮度
- 华为oj:名字的漂亮度
- 华为oj名字的漂亮度
- 华为OJ:名字的漂亮度
- 华为OJ-名字的漂亮度
- 华为OJ 名字的漂亮度
- 【华为OJ】【033-名字的漂亮度】
- [华为OJ] 名字的漂亮度
- 【华为OJ】名字的漂亮度
- 华为OJ 初级:名字的漂亮度
- 华为OJ 名字的漂亮度
- 解决DM8168上电自动启动,不需要手动登陆root
- 基于 SurfaceView 详解 android 幸运大转盘,附带实例app
- 补丁比较工具Darun Grim使用
- POJ 2029
- HDU 5389 Zero Escape(DP + 滚动数组)
- 华为OJ平台试题 —— 字符串:名字的漂亮度
- Hadoop 原理总结
- 初识Javascript的面向对象
- POJ3903 Stock Exchange
- POJ 1163 The Triangle(三种搜索方式)
- hdu 2602 Bone Collector(01背包)
- libpcap动态链接库在linux下使用以及接口函数
- UIButton中setTitleEdgeInsets和setImageEdgeInsets的使用
- 黑马程序员-----Java基础-----异常