公式

A - Yay! 解説 by en_translator


For beginners

There are various ways to solve this problem. One is to check inspect the \(i\)-th character and check if it is different from the others, for each \(i=1,2,\ldots,N\). To compare characters, use an if statement.

To inspect each character, you need to write a double for loop. Refer to the sample code, and also the reference of the language you use.

The following is sample code in C++ language.

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

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

投稿日時:
最終更新: