用字典树可解,但是STL要方便些
#include<bits/stdc++.h> using namespace std; map<string,int>m; int main() { int n,ans=0; scanf("%d",&n); string s; while(n--) { cin>>s; m[s]++; reverse(s.begin(),s.end()); if(m[s]) ans++; } printf("%d\n",ans); return 0; }
用字典树可解,但是STL要方便些
#include<bits/stdc++.h> using namespace std; map<string,int>m; int main() { int n,ans=0; scanf("%d",&n); string s; while(n--) { cin>>s; m[s]++; reverse(s.begin(),s.end()); if(m[s]) ans++; } printf("%d\n",ans); return 0; }