http://acm.hdu.edu.cn/showproblem.php?pid=2027
利用数组下标和ascii码的性质存储数据
View Code
1 #include<stdio.h> 2 int main() 3 { 4 int a[26],i,n; 5 char s[200]; 6 scanf("%d",&n); 7 gets(s); 8 while(n--) 9 {gets(s); 10 for(i=0;i<26;i++) 11 a[i]=0; 12 for(i=0;s[i]!='\0';i++) 13 if(s[i]>='a'&&s[i]<='z') 14 a[s[i]-'a']++; 15 printf("a:%d\n",a['a'-97]); 16 printf("e:%d\n",a['e'-97]); 17 printf("i:%d\n",a['i'-97]); 18 printf("o:%d\n",a['o'-97]); 19 printf("u:%d\n",a['u'-97]); 20 if(n) 21 printf("\n"); 22 } 23 return 0; 24 }