[백준] 1919번 애너그램 만들기 (배열, C++)

728x90
반응형

https://www.acmicpc.net/problem/1919

 

1919번: 애너그램 만들기

두 영어 단어가 철자의 순서를 뒤바꾸어 같아질 수 있을 때, 그러한 두 단어를 서로 애너그램 관계에 있다고 한다. 예를 들면 occurs 라는 영어 단어와 succor 는 서로 애너그램 관계에 있는데, occurs

www.acmicpc.net

 

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int num[26];

int main(void) {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	string s;
	cin >> s;
	for (auto c : s) {
		num[c - 'a']++;
	}
	cin >> s;
	for (auto c : s) {
		num[c - 'a']--;
	}
	int ans = 0;
	for (auto n : num) {
		if (n != 0) {
			ans += abs(n);
		}
	}
	cout << ans;
	
	return 0;
}
728x90
반응형
TAGS.

Comments