程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> 499 - Whats The Frequency, Kenneth?

499 - Whats The Frequency, Kenneth?

編輯:C#入門知識

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 make,dbx, and RCS, 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 editormore powerful than words. Further, for each instantiation vi hitherto, the Engineer responsible shalt performPenance. And lo, the Penance wilt be painful; there will be much wailing and gnushingof teeth. The Engineerwill 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 alphabeticallist 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[cpp]
#include<stdio.h>  
#include<string.h>  
int max(int *a) 

    int i,max=0; 
    for(i=0;i<52;i++) 
        if(a[i]>max) max=a[i]; 
    return max; 

int main(void) 

    char a[100]={0}; 
 
    while((gets(a))!=NULL) 
    { 
        int count[52]={0},i; 
        for(i=0;i<strlen(a);i++) 
        { 
            if(a[i]<='z'&&a[i]>='a') 
                count[a[i]-'a'+26]++; 
            else if(a[i]<='Z'&&a[i]>='A') 
                count[a[i]-'A']++; 
        } 
        for(i=0;i<52;i++) 
            if(count[i]==max(count)) 
            { 
                if(i<26) 
                    putchar(i+'A'); 
                else 
                    putchar(i+'a'-26); 
            } 
            printf(" %d\n",max(count)); 
    } 
    return 0; 

#include<stdio.h>
#include<string.h>
int max(int *a)
{
 int i,max=0;
 for(i=0;i<52;i++)
  if(a[i]>max) max=a[i];
 return max;
}
int main(void)
{
 char a[100]={0};

 while((gets(a))!=NULL)
 {
  int count[52]={0},i;
  for(i=0;i<strlen(a);i++)
  {
   if(a[i]<='z'&&a[i]>='a')
    count[a[i]-'a'+26]++;
   else if(a[i]<='Z'&&a[i]>='A')
    count[a[i]-'A']++;
  }
  for(i=0;i<52;i++)
   if(count[i]==max(count))
   {
    if(i<26)
     putchar(i+'A');
    else
     putchar(i+'a'-26);
   }
   printf(" %d\n",max(count));
 }
 return 0;
}

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved