题解:P14747 相似字符串

· · 题解

a water problem.

思路

统计两个字符串中不同的字符个数和相似情况的出现次数,若二者相等,则两个字符串是相似的。

特别的,如果二者皆为 0 无需特判,因为这样也视为两个字符串相似,且程序会输出正确结果。

AC CODE

#include<bits/stdc++.h>
using namespace std;
string s,t;
int s1,t1;
main(){
    cin>>s>>t;
    for(int i=0;i<s.size();i++){
        if(s[i]!=t[i])s1++;
        if(s[i]=='I' and t[i]=='l')t1++;
        if(s[i]=='l' and t[i]=='I')t1++;
    }
    if(s1==t1)cout<<"YES";
    else cout<<"NO";
}