luogu 集合刷题

p3405

// 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;

}

posted @ 2021-02-08 20:15  安之若醇  阅读(55)  评论(0编辑  收藏  举报
Live2D服务支持