백준 1919 애너그램

JunSeok·2023년 1월 3일
0

백준

목록 보기
2/40

백준 11328 문제와 유사하다.
11328 문제의 best solution을 이용하여 쉽게 풀었다.

내 풀이

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

int main(void){
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s1, s2;
    int a[26] = {}, value = 0;
    cin >> s1 >> s2;
    for(char c : s1) a[c-'a']++;
    for(char c : s2) a[c-'a']--;
    
    for(int i : a) if(i != 0) value += abs(i);
    cout << value;
}

새롭게 알게 된 점

인자의 절댓값을 반환해주는 abs function
유용히 사용할 것 같다.

profile
최선을 다한다는 것은 할 수 있는 한 가장 핵심을 향한다는 것

0개의 댓글