#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>
using namespace std;
int a[60], b[60];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
char str[101];
int i;
cin >> str;
for (i = 0; str[i] != '\0'; i++)
{
if (str[i] >= 65 && str[i] <= 90)
a[str[i] - 64]++;
else
a[str[i] - 70]++;
}
cin >> str;
for (i = 0; str[i] != '\0'; i++)
{
if (str[i] >= 65 && str[i] <= 90)
b[str[i] - 64]++;
else
b[str[i] - 70]++;
}
for (i = 1; i <= 52; i++)
{
if (a[i] != b[i])
{
cout << "NO\n";
exit(0);
}
}
cout << "YES\n";
return 0;
}
1. 1~52까지
대문자부터 소문자의 개수를 담는 인덱스를 주어진 글자 수의 최대까지 미리 만들어준다.
2. 이후 문자열을 받아온 뒤 인덱스 별로 알파벳 대문자 소문자를 구분하여 그 개수를 체크해준다.
3. 체크된 알파벳 개수를 짝맞춰본뒤
만약 짝이 맞지 않다면 NO를 출력하고 프로그램을 종료하도록 한다.
4. 만약 짝이 맞지 않은 경우에 걸리지 않았다면
YES를 출력하고 프로그램이 종료된다.
'콘솔창 & 윈도우창 > 코딩 테스트' 카테고리의 다른 글
프로그래머스 lv.2 H-Index (0) | 2024.04.18 |
---|---|
에라토스테네스의 체를 응용한 소수 사이 수열 3896 (0) | 2024.04.12 |
백준 - 괄호 9012 (0) | 2024.01.29 |
프로그래머스 lv1 덧칠하기 (0) | 2023.11.17 |
프로그래머스 lv2 최댓값과 최솟값 c++ (0) | 2023.10.24 |