optimize_ofast's blog

By optimize_ofast, history, 7 weeks ago, In English

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;
  • Vote: I like it
  • -6
  • Vote: I do not like it