题目:https://www.patest.cn/contests/pat-a-PRactise/1063
代码:
#include<cstdio> #include<cstring> #include<cstdlib> #include<cmath>#include<set>#include<algorithm> using namespace std; set<int> s[55];void compare(int a,int b){ int total = s[b].size(),same=0; for(set<int>::iterator i=s[a].begin();i!=s[a].end();i++){ if(s[b].find(*i) !=s[b].end()) same++; else total ++; } printf("%.1f%/n",same*100.0/total);}int main() { int n,a,b,k,t,qe; scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d",&k); for(int j=0;j<k;j++){ scanf("%d",&t); s[i].insert(t); } } scanf("%d",&qe); for(int i=0;i<qe;i++){ scanf("%d%d",&a,&b); compare(a,b); } system("pause"); }
新闻热点
疑难解答