华为机试练习150817第一题:名字的漂亮度
2015-08-18 09:16
204 查看
import java.util.Arrays; import java.util.Scanner; /** * Created by cq on 2015/8/17. */ public class Main { public static void main(String[] args){ Scanner in = new Scanner(System.in); int nameNum = in.nextInt(); in.nextLine(); for (int i=0; i<nameNum; i++){ String s = in.nextLine(); System.out.println(beautyScore(s)); } in.close(); } public static int beautyScore(String name){ name = name.toLowerCase(); int len = name.length(), score = 0; //计数 int[] records = new int[26]; for(int i=0; i<len; i++){ char alp = name.charAt(i); records[alp-'a']++; } //升序排序 Arrays.sort(records); //计分 int index = 25; while (records[index] != 0){ score += (records[index]*(index+1)); index--; } return score; } }
相关文章推荐
- nginx搭建tcp代理服务器
- leetcode 150 —— Evaluate Reverse Polish Notation
- Scala实战-通过微信聊天窗口实现应答式点餐 0
- (精)前后端分离的思考与实践(一)
- POJ - 2532 Stars
- mysql新建用户及授权
- awk length
- B. Vanya and Books( Codeforces Round #308 (Div. 2) 简单题)
- 阿里云服务器9折优惠券分享
- AltiumDesigner97——封装_L_M_N的区别
- linux文件系统十问
- 德州扑克胜率计算
- HDOJ 1242 Rescue【BFS】
- 一个简单的时间获取客户端程序
- [noip2013]货车运输(kruskal + 树上倍增)
- [Leetcode] Linked List Cycle II
- 面向对象和面向过程
- 串口之COMMTIMEOUTS结构体详解
- hdu2454 Degree Sequence of Graph G(havel定理)
- HDU 4513 吉哥系列故事——完美队形II(Manacher算法最大回文长度 && 两侧沿中点递减)