題目描述
老師有一個問題想考考mabo,但是mabo不會,是以想請你來幫幫忙。
問題如下:
給一串字元串,統計其中某個字元的個數。
輸入格式
首先輸入一個整數T,表示一共有T組資料 0 < T<=10。
接下來每行一個字母x(x為’a’-‘z’或者‘A’-‘Z’)。
然後下面一行輸入一個字元串s(0 < s的長度<1000)。
輸出格式
統計這個字母在這個字元串中出現的次數
#include <stdio.h>
#include <iostream>
using namespace std;
int main(){
int t,T;
cin>>T;
for(t=;t<=T;t++){
char x;
cin>>x;
char str[];
scanf("%s",str);
int i;
int count=;
for(i=;str[i]!='\0';i++){
if(str[i]==x)
count++;
}
cout<<count<<endl;
}
return ;
}