# UVa 1339 - Ancient Cipher --- # 題目大意 給兩字串,問能否將第一個字串隨意排列及將字母一一變換後得到第二個字串。字母一一變換是指一種字母只能變成一種字母。 --- # 題解 因為可以任意排列,所以只要看不同的字母數量是否相同即可。 --- ```=C++ #include <bits/stdc++.h> #define ll long long #define pb push_back #define INF 2147483647 #define ft first #define sec second #define pr pair<int,int> #define ISCC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); using namespace std; int t ,n ,m; string s1 ,s2; int main() { ISCC; while(getline(cin,s1)) { getline(cin,s2); int cnt1[26]={0} ,cnt2[26]={0} ,ok=1; for(int i=0 ;i<s1.size() ;i++) { cnt1[s1[i]-'A']++; cnt2[s2[i]-'A']++; } sort(cnt1 ,cnt1+26); sort(cnt2 ,cnt2+26); for(int i=0 ;i<26 ;i++) if(cnt1[i]!=cnt2[i]){ok=0; break;} cout << (ok?"YES\n":"NO\n"); } return 0; } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up