1 solutions
-
0
算法分析
出现过的字符就做对应的标记
#include<bits/stdc++.h> using namespace std; const int N=2e5+10,M=200; char s[N],t[N]; int fs[M],ft[M]; int main() { cin>>s>>t; int n=strlen(s); bool st=true; for(int i=0;i<n;i++) { if(fs[s[i]]==0) //没有出现过 { fs[s[i]]=t[i]; //标记变化 } else //已经有了看是否匹配 { if(fs[s[i]]!=t[i]) { st=0; //不相等一定不可以 break; } } if(ft[t[i]]==0) //同步更新 { ft[t[i]]=s[i]; } else { if(ft[t[i]]!=s[i]) { st=0; //不相等一定不可以 break; } } } if(st) cout<<"Yes"<<endl; //符合要求 else cout<<"No"<<endl; //不符合要求 return 0; }
- 1
Information
- ID
- 1625
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 10
- Tags
- # Submissions
- 2
- Accepted
- 1
- Uploaded By