My tutorial of "Codeforces Round 927 (Div. 3) A. Thorns and Coins"

Правка en1, от optimize_ofast, 2024-02-20 12:38:25

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; } ~~~~~

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en3 Английский optimize_ofast 2024-02-20 12:42:39 12 Tiny change: '::npos) { //找到了连续的两根刺 \n ' -> '::npos) { \n '
en2 Английский optimize_ofast 2024-02-20 12:39:07 2 Tiny change: 'he code:\n~~~~~\n#' -> 'he code:\n\n~~~~~\n#'
en1 Английский optimize_ofast 2024-02-20 12:38:25 872 Initial revision (published)