Блог пользователя optimize_ofast

Автор optimize_ofast, история, 7 месяцев назад, По-английски

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;
}
  • Проголосовать: нравится
  • +5
  • Проголосовать: не нравится

»
7 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by optimize_ofast (previous revision, new revision, compare).

»
7 месяцев назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

You could append "**" to the input string as a sentinel to simplify your code.

Look at the solve() function here.