srupのメモ帳

競プロで解いた問題や勉強したことを記録していくメモ帳

SRM 689 div2 easy SimilarUserDetection

問題

問題概要

文字列がいくつか与えられる。その文字列のなかに同じものが2つ以上あるかを判別する。ただし、0(ゼロ)とO(オー)は同じもの、1(いち)とl(Lの小文字)とI(iの大文字)は同じものとして考える。

解法

方針としては、文字列を変換して、重複を確認する。
まず、0(ゼロ)とO(オー)に、l(Lの小文字)とI(iの大文字)を1(いち)に変換する。次に、それをsetにいれて、重複を消し、setの中に入っている数と、もともとあった文字列の総数が一致していれば同じ文字列はなかったことになる。

ミス

先に変換しておくとだいぶ楽。

コード

#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
#include <set>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
const int INF = 1e9;

class SimilarUserDetection{
public:
    string haveSimilar(vector <string> handles){
        rep(i, handles.size()){
            rep(j, handles[i].size()){
                if(handles[i][j] == '0') handles[i][j] = 'O';
                else if(handles[i][j] == 'l') handles[i][j] = '1';
                else if(handles[i][j] == 'I') handles[i][j] = '1';
            }
        }

        set<string> s;
        for (int i = 0; i < handles.size(); ++i){
            s.insert(handles[i]);
        }
        if(s.size() == handles.size()){
            return "Similar handles not found";
        }else{
            return "Similar handles found";
        }
    }
};