1.set
1 #include <cstdio> 2 #include <cstdlib> 3 #include <cstring> 4 #include <cmath> 5 #include <list> 6 #include <stack> 7 #include <vector> 8 #include <set> 9 #include <map> 10 #include <queue> 11 #include <algorithm> 12 #include <iostream> 13 using namespace std; 14 15 //ÿ¸öµ¥´ÊÖ»³öÏÖÒ»´Î,¼´Ò»¸öµ¥´ÊÖÁ¶àÓëÆäËüµ¥´ÊÅäºÏÒ»±é 16 set<string> f; 17 18 int main() 19 { 20 string s,t; 21 long n; 22 long sum=0; 23 scanf("%ld",&n); 24 while (n--) 25 { 26 cin>>s; 27 if (f.find(s)!=f.end()) 28 sum++; 29 30 t=s; 31 reverse(t.begin(),t.end()); 32 f.insert(t); 33 } 34 printf("%lld ",sum); 35 return 0; 36 }
2.map
1 #include <cstdio> 2 #include <cstdlib> 3 #include <cstring> 4 #include <cmath> 5 #include <list> 6 #include <stack> 7 #include <vector> 8 #include <set> 9 #include <map> 10 #include <queue> 11 #include <algorithm> 12 #include <iostream> 13 using namespace std; 14 15 map<string,long> f; 16 17 int main() 18 { 19 string s,t; 20 long n; 21 long long sum=0; 22 scanf("%ld",&n); 23 while (n--) 24 { 25 cin>>s; 26 t=s; 27 reverse(t.begin(),t.end()); 28 sum=sum+(long long)f[t]*f[t]; 29 f[s]++; 30 } 31 printf("%lld ",sum); 32 return 0; 33 }