浙工ACM1242

来源:互联网 发布:c语言 日期间隔 编辑:程序博客网 时间:2024/05/16 12:36
 #include<iostream>
#include<string>
using namespace std;
int main(){
string s;
int *a = new int[26];
for(int k =0;k < 26;k++)
a[k] = 0;
int i,j;
while(cin>>s)
{
       for(i = 0;i < s.length();i++)
   {
   if(s[i] != '#')
   a[(char)s[i] - 97]++;
   }
   if(s[i-1] == '#')
     for( j =0;j < 26;j++)
   cout<<(char)(j + 97)<<" "<<a[j]<<endl;
}
return 0;
}


  a[(char)s[i] - 97]++;

典型的统计字母的方法!!!

 cout<<(char)(j + 97)<<" "<<a[j]<<endl;