Tutorial of "HUAWEI Programming Contest 2024(Atcoder Beginner Contest 342)"

Revision en1, by optimize_ofast, 2024-02-27 03:42:13

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;
    }
}
Tags string, implementations, brute force

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English optimize_ofast 2024-02-27 03:42:13 1358 Initial revision (published)