zoukankan      html  css  js  c++  java
  • [解题报告]499 What's The Frequency, Kenneth?

     What's The Frequency, Kenneth? 
    #include <stdio.h>
    
    main()
    {
      int i;
      char *suffix[]= { "st", "nd", "rd" };
      char *item[]= { "Unix" , "cat", "sed", "awk", "grep", "ed", "vi"};
     
      printf("In the beginning, there was nothing.\n");
      for (i= 0; i < 7; i++)
        printf("And on the %d%s day, God created %s. And it was good.\n",
               i + 1, (i < 3) ? suffix[i] : "th", item[i]);
    }

    But then God saw that vi led people into temptation. Instead of choosing the righteous ways of makedbx, andRCS, people used long command lines, printf(), and tape backups.

    So God decreed, ``I see that Engineers have thus defiled my vi. And so, I shall create emacs, an editor more powerful than words. Further, for each instantiation vi hitherto, the Engineer responsible shalt perform Penance. And lo, the Penance wilt be painful; there will be much wailing and gnushingof teeth. The Engineer will read many lines of text. For each line of text, the Engineer must tell me which letters occur the most frequently.''

    ``I charge you all with My Golden Rule: 'Friends shalt not let friends use vi'.''

    Input and Output

    Each line of output should contain a list of letters that all occured with the highest frequency in the corresponding input line, followed by the frequency.

    The list of letters should be an alphabetical list of upper case letters followed by an alphabetical list of lower case letters.

    Sample Input

    When riding your bicycle backwards down a one-way street, if the
    wheel falls of a canoe, how many ball bearings does it take to fill
    up a water buffalo?
    Hello Howard.

    Sample Output

    e 6
    al 7
    a 3
    Hlo 2


    学会使用memset函数

    void *memset(void *s,int ch,size_t n);
    函数解释:将 s 中前 n 个字节用 ch 替换并返回 s 。
    memset:作用是在一段内存块中填充某个给定的值,它是对较大的结构体或数组进行清零操作的一种最快方法。

    把一个char a[20]清零,一定是 memset(a,0,20);

    (地址,要赋予的值,连续几个字节)

    #include <stdio.h>
    #include <string.h>
    #define MAX(x,y) (x>y?x:y)
    char str[1234567];
    int num[256];
    
    int main()
    {
        int i;
        int max;
        while(gets(str))
        {
            if(str[0]=='\0')continue;
            memset(num,0,sizeof(num));
            for(i=0;str[i]!='\0';++i)++num[(int)str[i]];
            max = 0;
            for(i='A';i<='Z';++i)max = MAX(max,num[i]);
            for(i='a';i<='z';++i)max = MAX(max,num[i]);
            for(i='A';i<='Z';++i)if(num[i]==max)putchar(i);
            for(i='a';i<='z';++i)if(num[i]==max)putchar(i);
            printf(" %d\n",max);
    
        }
        return 0;
    }
  • 相关阅读:
    stl的stack在开发中的应用
    stl的stack在开发中的应用
    SQL Server遍历表中记录的2种方法
    SQL Server遍历表中记录的2种方法
    SQL Server遍历表中记录的2种方法
    SQL Server遍历表中记录的2种方法
    struts中用kindeditor实现的图片上传并且显示在页面上
    struts中用kindeditor实现的图片上传并且显示在页面上
    struts中用kindeditor实现的图片上传并且显示在页面上
    区块链协议新方向-图灵奖得主Macali开发Algorand
  • 原文地址:https://www.cnblogs.com/TheLaughingMan/p/2924688.html
Copyright © 2011-2022 走看看