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

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

Hello, codeforces!

Before starting to explain the topic, what I want to say is that in some of the solutions I have previously published, some highly skilled people have said that my solutions are "redundant", and they prefer to see the official solutions rather than the ones written by others. Perhaps there is a slight deviation in my understanding, but my level is indeed very limited. The solution I provided is my personal opinion, so I don't think it's unnecessary. Because my coding ability is not very high, I hope everyone can give me more encouragement, okay?

Today, I will provide the solution to question A in this competition.

This is just a easy string simulation. We just need to define a variable "flag" to determine if the different character has been found. Because the essence of a string is a character array, its minimum index is 0. So we need to add 1 to the number.

This is the AC Code:

#include <bits/stdc++.h>
using namespace std;

string s;
int main(){
    cin >> s;
    int n = s.length();
    for(int i = 0; i < n; i++) {
        bool flag = true;
        for(int j = 0; j < n; j++) {
            if(i != j and s[i] == s[j]) flag = false;
        }
        if(flag == true) cout << i + 1 << endl;
    }
}

Полный текст и комментарии »

  • Проголосовать: нравится
  • -6
  • Проголосовать: не нравится

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

This question is quite easy!

We only need to input t sets of data and traverse each string. And use two counters, "suma" and "sumb", to determine the number of occurrences of letter A and letter B, and compare them.

It is worth noting that the title has already mentioned that the length of the string is 5, so we do not need to determine whether suma is equal to sumb.

Hope to see your comments!

Below is the AC code:

#include <bits/stdc++.h>
using namespace std;

int t;
int main() {
	cin >> t;
	while(t--) {
		string s;
		cin >> s;
		int suma = 0, sumb = 0;
		for(int i = 0; i < s.length(); i++) {
			if(s[i] == 'A') suma++;
			else sumb++;
		}
		if(suma > sumb) cout << "A" << endl;
		else cout << "B" << endl;
	}
	return 0;
}

Полный текст и комментарии »

  • Проголосовать: нравится
  • -5
  • Проголосовать: не нравится

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

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