HDU AC Me

来源:互联网 发布:游戏主机 知乎 编辑:程序博客网 时间:2024/05/19 00:17

题目传送门:
http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=1&sectionid=2&problemid=26
由于输入全部都是小写字母a-z(0x61H-0x61+25),因此我们使用数组的时候有个技巧,可以将其减去0x61H映射到0-25的集合中去,而这个集合就作为times(出现次数)数组,剩下的就是输入输出问题了。

#include<stdio.h>#include<string.h>using namespace std;//HDU AC Meint time[26]={0};int main(){    //freopen("input.txt","r",stdin);    char buffer[1000000];  //数组开大一点,否则会出错,注意题目要求    //gets可以读空格,但是scanf不可以    while(gets(buffer)!=0){        int len=strlen(buffer);        for(int i=0;i<len;i++){            if(buffer[i]>=0x61 &&buffer[i]<=0x61+25)                time[buffer[i]-0x61]++;        }        for(int j=0;j<26;j++){            printf("%c:%d\n",0x61+j,time[j]);        }        printf("\n");        memset(time,0,sizeof(time));    }    return 0;}
0 0
原创粉丝点击