生活随笔
收集整理的這篇文章主要介紹了
752B
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
貪心\字符串\1500
大意:一個鍵盤鍵帽裝錯了 a是打出來的字符串 b是鍵帽上顯示的 求已知的錯位鍵
wa1:忘記統計正確的鍵帽 e.g, aa ab 是矛盾的
wa2:忘輸出總數。。
wa3:矛盾判斷條件為:an和bn中有一個被判斷過,且an對應的值不等于bn,錯誤在只判斷an,導致ab aa這類 未判-1
#include<bits/stdc++.h>
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define fi for(int i=1;i<=n;i++)
#define fi2 for(int i=0;i<n;i++)
using namespace std
;
typedef long long ll
;
typedef vector
<int> vi
;
typedef set
<int> si
;
const ll inf
=0x3f3f3f3f3f3f3f3f;
const int INF
=0x3f3f3f3f;
const int MAX
=2e5+10;
string s1
,s2
;
int ans
[26];
int v
[26];
int pp
,sum
;
int main(){for(int i
=0;i
<26;i
++){ans
[i
]=-1;}cin
>>s1
;cin
>>s2
;for(int i
=0;i
<s1
.size();i
++){if(ans
[s1
[i
]-'a']!=-1||ans
[s2
[i
]-'a']!=-1){if(ans
[s1
[i
]-'a']!=s2
[i
]-'a'){cout
<<"-1";return 0;} }else {ans
[s1
[i
]-'a']=s2
[i
]-'a';ans
[s2
[i
]-'a']=s1
[i
]-'a';}
}for(int i
=0;i
<26;i
++){if(ans
[i
]!=i
&&ans
[i
]!=-1)sum
++;}cout
<<sum
/2<<endl
;for(int i
=0;i
<26;i
++){if(ans
[i
]!=i
&&ans
[i
]!=-1&&v
[i
]==0){v
[i
]=1;v
[ans
[i
]]=1;cout
<<(char)(i
+'a')<<' '<<(char)(ans
[i
]+'a')<<endl
;}}
}
總結
以上是生活随笔為你收集整理的752B的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。