ACM-ICPC 2018 徐州赛区网络预赛
I. Characters with Hash
签到, 找第一个不为零的。
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
const int N = 1e6 + 10;
const int M = 1e2 + 5;
int _, n;
char c;
char str[N];
int main(){
for(scanf("%d", &_); _; _--){
scanf("%d%c%c", &n, &c, &c);
getchar();
scanf("%s", str);
int len = strlen(str);
int ans = 0;
for(int i = 0; i < len; i++){
int num = abs(str[i] - c);
if(num){
if(num < 10)
ans = (len - i - 1) * 2 + 1;
else
ans = (len - i - 1) * 2 + 2;
printf("%d\n", ans);
goto end;
}
}
printf("1\n");
end: ;
}
return 0;
}