等价多米诺骨牌对的数量(C语言)
题目描述
给你一个由一些多米诺骨牌组成的列表 dominoes。
如果其中某一张多米诺骨牌可以通过旋转 0 度或 180 度得到另一张多米诺骨牌,我们就认为这两张牌是等价的。
形式上,dominoes[i]=[a,b] 和 dominoes[j]=[c,d] 等价的前提是 a==c 且 b==d,或是 a==d 且 b==c。
在 0<=i<j<dominoes.length 的前提下,找出满足 dominoes[i] 和 dominoes[j] 等价的骨牌对 (i,j) 的数量。
输入格式
一个数组列表。
输出格式
一个整数。
输入输出样例
输入
[[1,2],[2,1],[3,4],[5,6]]
输出
1
说明/提示
1<=dominoes[i][j]<=9
#include<stdio.h>
typedef struct demi{int right;int left;
}de;
int main ()
{char st;char stop=',';int x,y;int cnt=0;int res=0;de dominoes[11];scanf("%c",&st);while(stop==','){scanf("%c",&st);scanf("%d%c%d",&x,&st,&y);scanf("%c",&st);cnt++;dominoes[cnt].left=x;dominoes[cnt].right=y;scanf("%c",&stop);}for(int i=1;i<=cnt;i++){for(int j=i+1;j<=cnt;j++){if((dominoes[i].left==dominoes[j].left&&dominoes[i].right==dominoes[j].right)||(dominoes[i].left==dominoes[j].right&&dominoes[i].right==dominoes[j].left))res++;}}printf("%d",res);return 0;
}