注意几种情况,前导零是不要的;如果在开头的第一个值为个位数,那么占一位,如果个位数出现在中间,那么占两位,比如6就是06
#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;
int main(void)
{
int T;
scanf("%d",&T);
while(T--){
int n,cnt=0;//cnt用来计数
char z,s;
cin >> n >> z;
for(int i=0;i<n;i++){
cin >> s;
if(s == z && cnt==0)
continue;
else if((abs(s-(z)))<=9 && cnt==0)
cnt+=1;
else
cnt += 2;
}
if(cnt == 0)
cout <<"1\n";
else//这个else很重要
cout << cnt <<endl;
}
return 0;
}