luogu 集合刷题
// made by Arc on 2021/2/8
//Luogu p3405
#include<bits/stdc++.h>
using namespace std;
map<int,int>mmp[100008];
int n,ans;
int main()
{
cin>>n;
for(int i=1;i<=n;i++){
string a,b;
cin>>a>>b;
//hash:字符串变数字
int A=a[0]*26+a[1];
int B=b[0]*26+b[1];
ans+=mmp[B][A];
//防止有自身相等的情况
if(A==B)ans-=mmp[A][B];
mmp[A][B]++;
}
printf("%d",ans);
return 0;
}
为了自己,和那些爱你的人