정답 코드
#include <iostream>
#include <algorithm>
using namespace std;
int n;
string base;
int ans;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>base;
int len = base.size();
for(int i=0; i<n-1; i++) {
string comp;
cin>>comp;
int compLen = comp.size();
int cnt=0;
for(int j=0; j<len; j++) {
for(int k=0; k<compLen; k++) {
if(base[j] == comp[k]) {
cnt++;
comp[k] = ' ';
break;
}
}
}
if(compLen-cnt<=1 && len-cnt<=1) {
ans++;
}
}
cout<<ans<<'\n';
return 0;
}
처음에 compLen-cnt<=1 조건만 넣었다가 틀렸다. 조건을 꼼꼼하게 비교하자!