UVa1339

題目:
https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=446&page=show_problem&problem=4085

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <bits/stdc++.h>
using namespace std;

int main(){
ios::sync_with_stdio(0);
cin.tie(0);

string s1, s2;
while(cin >> s1 >> s2){
vector<int> a(26,0), b(26,0); // 紀錄出現次數的vector
for(char c : s1){
++a[c-'A'];
}
for(char c : s2){
++b[c-'A'];
}

sort(a.begin(), a.end());
sort(b.begin(), b.end());
// sort兩個vector,確認出現次數的數量是否相同

bool equals = true;
for(int i=0; i<26; ++i){
if(a[i] != b[i]){
equals = false;
break;
}
}
if(equals) cout << "YES\n";
else cout << "NO\n";
}
return 0;
}