zoukankan      html  css  js  c++  java
  • 最大ASCII的和问题

    问题:One day when you are going to clear all your browsing history, you come up with an idea: You want to figure out what your most valued site is. Every site is given a value which equals to the sum of ASCII values of all characters in the URL. For example aa.cc has value of 438 because 438 = 97 + 97 + 46 + 99 + 99. You just need to print the largest value amongst all values of sites.
    Things are simplified because you found that all entries in your browsing history are of the following format: [domain], where [domain] consists of lower-case Latin letters and “.” only. See the sample input for more details.
     
    Input
    There are several test cases.
    For each test case, the first line contains an integer n (1 ≤ n ≤ 100), the number of entries in your browsing history.
    Then follows n lines, each consisting of one URL whose length will not exceed 100.
    Input is terminated by EOF.
     
    Output
    For each test case, output one line “Case X: Y” where X is the test case number (starting from 1) and Y is a number indicating the desired answer.
     
    Sample Input
    1
    aa.cc
    2
    www.google.com
    www.wikipedia.org

    Sample Output
    Case 1: 438
    Case 2: 1728

    回答:题意就是给n个字符串,求最大ASCII码和。

    #include <stdio.h>
    #include <string.h>

    int main() {
        int n, t = 0;
        while(scanf("%d", &n)!=EOF) {
            int maxx = 0;
            while(n--) {
                int i, tmp = 0;
                char s[105];
                scanf("%s", s);
                for(i = 0; s[i]; i++)
                    tmp += s[i];
                if(tmp > maxx)
                    maxx = tmp;
            }
            printf("Case %d: %d ", ++t, maxx);
        }
        return 0;
    }

  • 相关阅读:
    Flex 布局教程:语法篇(转载)
    【Go】【Http】Go实现Http相关知识点
    【Git】Git相关开发流程
    【Go】杂七杂八GoLang
    【Go】初识Context与Context键值对的可能情况
    jmeter-通过json提取器 提取所有数据 给下个接口使用
    C# 后台调用存储过程超时处理方法,
    IE11脚本错误-调用的对象无效-
    IE11浏览器arrt,全选反选失效无效修改方法
    如何学习计算机知识
  • 原文地址:https://www.cnblogs.com/benchao/p/4639632.html
Copyright © 2011-2022 走看看