90分求助

P1071 [NOIP2009 提高组] 潜伏者

```cpp #include<bits/stdc++.h> using namespace std; string s,s1,s2; long long a[100],cnt; long long b[100]; int main(){ memset(a,-1,sizeof(a)); memset(b,-1,sizeof(b)); cin>>s1>>s2>>s; long long len=s1.size(); for(int i=0;i<len;i++){ if(a[s1[i]-'A']!=(s2[i]-'A')){ if(a[s1[i]-'A']==-1)a[s1[i]-'A']=(s2[i]-'A'); else{ cout<<"Failed"; return 0; } } } for(int i=0;i<len;i++){ if(b[s2[i]-'A']!=(s1[i]-'A')){ if(b[s2[i]-'A']==-1) b[s2[i]-'A']=(s1[i]-'A'); else{ cout<<"Failed"; return 0; } } } for(int i=0;i<26;i++)if(a[i]==-1)cnt++; if(cnt){ cout<<"Failed"; return 0; } long long len2=s.size(); for(int i=0;i<len2;i++)cout<<char(a[s[i]-'A']+'A'); return 0; } ``` @[Wpy123456](/user/739742)
by meng_cen @ 2023-10-05 12:37:20


不仅要判断s1,s2也要在判断一遍。因为题中说一个密文对应的字母只有1个,防止有多个密文代表同一个字母
by meng_cen @ 2023-10-05 12:39:11


加了 ```cpp long long b[100]; memset(b,-1,sizeof(b)); for(int i=0;i<len;i++){ if(b[s2[i]-'A']!=(s1[i]-'A')){ if(b[s2[i]-'A']==-1) b[s2[i]-'A']=(s1[i]-'A'); else{ cout<<"Failed"; return 0; } } } ```
by meng_cen @ 2023-10-05 12:40:29


90分错的那个点: ```cpp QWERTYUIOPLKJHGFDSAZXCVBNM QWERTYUIOPLKJHGFDSAZXCVBNN HIJACK ``` 其中,**N**和**M**都代表**N**,所以输出**Failed**
by meng_cen @ 2023-10-05 12:42:13


@[Wpy123456](/user/739742) 王兄,这可不想你会错的题哦_QAQ_
by meng_cen @ 2023-10-05 12:42:54


@[meng_cen](/user/797897) 多谢孟兄
by Wpy123456 @ 2023-10-06 20:56:15


|