If there are "spikes" in two or more consecutive cells, then only the quantity of all previous coins needs to be counted;↵
If there are no consecutive $2 $or more cells with spikes, it can be proven that we can definitely reach the last cell.↵
↵
So this is the code:↵
↵
~~~~~↵
#include <bits/stdc++.h>↵
using namespace std;↵
↵
int sum = 0;↵
int main() {↵
int t;↵
cin >> t;↵
while (t--) {↵
int n, now = 0;↵
string s;↵
cin >> n >> s;↵
int sum = 0;↵
if(s.find("**") != string::npos) { //找到了连续的两根刺 ↵
for(int i = 0; i < s.find("**"); i++) {↵
if(s[i] == '@') sum++;↵
}↵
cout << sum << endl;↵
}↵
else {↵
for(int i = 0; i < s.length(); i++) {↵
if(s[i] == '@') sum++;↵
}↵
cout << sum << endl;↵
}↵
}↵
return 0;↵
}↵
~~~~~↵
↵
↵
If there are no consecutive $2 $or more cells with spikes, it can be proven that we can definitely reach the last cell.↵
↵
So this is the code:↵
↵
~~~~~↵
#include <bits/stdc++.h>↵
using namespace std;↵
↵
int sum = 0;↵
int main() {↵
int t;↵
cin >> t;↵
while (t--) {↵
int n, now = 0;↵
string s;↵
cin >> n >> s;↵
int sum = 0;↵
if(s.find("**") != string::npos) { //找到了连续的两根刺 ↵
for(int i = 0; i < s.find("**"); i++) {↵
if(s[i] == '@') sum++;↵
}↵
cout << sum << endl;↵
}↵
else {↵
for(int i = 0; i < s.length(); i++) {↵
if(s[i] == '@') sum++;↵
}↵
cout << sum << endl;↵
}↵
}↵
return 0;↵
}↵
~~~~~↵
↵
↵