zoukankan      html  css  js  c++  java
  • 名字的漂亮度

     1 // 12345.cpp : Defines the entry point for the console application.
     2 //
     3 
     4 #include "stdafx.h"
     5 
     6 #include <iostream>
     7 #include <string>
     8 #include <algorithm>
     9 #include <vector>
    10 
    11 using namespace std;
    12 
    13 int main(void)
    14 {
    15     int N;
    16     
    17     while(cin>>N)
    18     {
    19         
    20         int *p = new int[N];
    21         string str;
    22         for(int j=0;j<N;++j)
    23         {
    24             cin>>str;
    25             vector<int> hash(26,0);
    26             for(int i=0;i < str.length();++i)
    27             {
    28                 hash[str[i]-'a']++;
    29             }
    30             sort(hash.begin(),hash.end());
    31             p[j]=0;
    32             int count=26;
    33             for(vector<int>::iterator it=hash.end()-1;it >= hash.begin();--it)
    34             {
    35                 p[j]=p[j]+(count--)*(*it);
    36             }
    37         }
    38         for(int k=0;k<N;++k)
    39         {
    40             cout<<p[k]<<endl;
    41         }
    42         delete [] p;
    43     }
    44 
    45     return 0;
    46 }

    描述

    给出一个名字,该名字有26个字符串组成,定义这个字符串的“漂亮度”是其所有字母“漂亮度”的总和。
    每个字母都有一个“漂亮度”,范围在1到26之间。没有任何两个字母拥有相同的“漂亮度”。字母忽略大小写。
    给出多个名字,计算每个名字最大可能的“漂亮度”。

    知识点 字符串
    运行时间限制 0M
    内存限制 0
    输入

    整数N,后续N个名字

    N个字符串,每个表示一个名字

    输出

    每个名称可能的最大漂亮程度

    样例输入 2 zhangsan lisi
    样例输出 192 101
  • 相关阅读:
    nginx 注册为服务
    使用Windows Service Wrapper快速创建一个Windows Service
    mongo数据导入导出
    msql数据导入导出
    sql server 数据库之间导入导出数据表
    性能问题核对清单
    常用sqlserver性能分析
    Jmeter压测Mysql示例
    nginx日志定制
    zookeeper集群部署
  • 原文地址:https://www.cnblogs.com/hhboboy/p/5671856.html
Copyright © 2011-2022 走看看