题解 | #计算某字符出现次数#
计算某字符出现次数
http://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1
#include #include #include
int main() { map<char,int>a; char mid; while ((mid = getchar()) != '\n') { if((mid>='A')&&(mid<='Z')) { mid=mid+'a'-'A'; } a[mid]++; } char T=getchar(); if((T>='A')&&(T<='Z')) { T=T+'a'-'A'; }
auto it=a.begin();
bool flag=false;
for(;it!=a.end();it++)
{
if((it->first)==T)
flag=true;
}
if( flag==true)
cout<<a[T]<<endl;
else{
cout<<0<<endl;
}
return 0;
}