Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define endl '\n'
- #define sz(x) int(x.size())
- #define all(x) x.begin(), x.end()
- bool is_anagram(string s, string t) {
- char freq[300]{};
- for (int i = 0; i < sz(s); i++) if (s[i] != ' ') freq[s[i]]++;
- for (int i = 0; i < sz(t); i++) if (t[i] != ' ') freq[t[i]]--;
- for (int i = 0; i < 300; i++) if (freq[i]) return false;
- return true;
- }
- int main() {
- ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
- int testcases;
- cin >> testcases;
- cin.ignore();
- cin.ignore();
- for (int test = 1; test <= testcases; test++) {
- if (test > 1) cout << endl;
- string lines[105];
- int sz = 0;
- while (getline(cin, lines[sz]), lines[sz++] != "");
- vector<string> ans;
- for (int i = 0; i < sz; i++) {
- for (int j = i + 1; j < sz; j++) {
- if (is_anagram(lines[i], lines[j])) {
- if (lines[i] < lines[j]) ans.push_back(lines[i] + " = " + lines[j]);
- else ans.push_back(lines[j] + " = " + lines[i]);
- }
- }
- }
- sort(all(ans));
- for (auto& I : ans) {
- cout << I << endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement