1일1알

백준 2607번 비슷한 단어 C++ 본문

알고리즘

백준 2607번 비슷한 단어 C++

영춘권의달인 2022. 9. 7. 10:02

출처 : https://www.acmicpc.net/problem/2607

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>

#include <bitset>

using namespace std;
using int64 = long long;

int n;

map<char, int> mp;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);

    cin >> n;
    string str;
    cin >> str;
    int len = str.length();
    for (int i = 0; i < len; i++) {
        mp[str[i]]++;
    }
    int ans = 0;
    for (int i = 0; i < n - 1; i++) {
        cin >> str;
        int wrongCnt = 0;
        map<char, int> tmpMp;
        for (auto a : mp) {
            tmpMp.insert({ a.first,a.second });
        }
        for (int j = 0; j < str.length(); j++) {
            tmpMp[str[j]]--;
        }
        for (auto a : tmpMp) {
            wrongCnt += abs(a.second);
        }
        if (str.length() == len) {
            if (wrongCnt <= 2) ans++;
        }
        else {
            if (wrongCnt <= 1) ans++;
        }
    }
    cout << ans;
}

'알고리즘' 카테고리의 다른 글

백준 1253번 좋다 C++  (0) 2022.09.09
백준 24391번 귀찮은 해강이 C++  (0) 2022.09.08
백준 20291번 파일 정리 C++  (0) 2022.09.06
백준 2146번 다리 만들기 C++  (0) 2022.09.05
백준 1937번 욕심쟁이 판다 C++  (0) 2022.09.04