HDU - 1219 AC Me(超级水题)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU - 1219 AC Me(超级水题)相关的知识,希望对你有一定的参考价值。

题意:给一句英语句子,求从a-z各出现了几次。

主要是给自己提一个醒for循环中要少调用函数,函数运行需要时间,再加上for循环的时间,很可能时间超限。

 1 #include<stdio.h>
 2 #include<string.h>
 3 #define M 100010
 4 int main(){
 5     char str[M];
 6     int count[M];
 7     while(gets(str)){
 8         memset(count,0,sizeof(count));
 9         int k=strlen(str);//非常重要 
10         for(int i=0;i<k;i++){
11             if(str[i]>=a&&str[i]<=z) count[str[i]-a]++;
12         }
13         for(int i=0;i<26;i++)
14         printf("%c:%d\n",a+i,count[i]);
15         printf("\n");
16     }
17     return 0;
18 }

 

以上是关于HDU - 1219 AC Me(超级水题)的主要内容,如果未能解决你的问题,请参考以下文章