标签:data view cstring 分享图片 iostream its c++ opened bsp
虽然一次过 但是感觉我方法很怪 不巧妙
#include<iostream> #include<cstring> #include <bits/stdc++.h> using namespace std; struct aaa { int num; int f; }a[1000]; bool cmp(struct aaa a1,struct aaa a2) { if(a1.f!=a2.f)return a1.f>a2.f; else return a1.num>a2.num; } int main(){ map<int ,int>ma; int n;cin>>n;int c=0; for(int i=1;i<=n;i++) { int k;cin>>k; while(k--) { int x;cin>>x; if(!ma.count(x)){ma[x]=c;a[c].f++;a[c].num=x;c++;} else a[ma[x]].f++; } } sort(a,a+c,cmp); printf("%d %d",a[0].num,a[0].f); return 0; }
非常简单。。。
#include <iostream> using namespace std; int book[1005] = {0}; int main() { int n; cin >> n; int count = 0; //被点赞最多的数量 int ans = 0; for(int i = 0; i < n; i++) { int x; cin >> x; for(int j = 0; j < x; j++) { int data; cin >> data; book[data]++; if(book[data] > count) { count = book[data]; ans = data; } else if(book[data] == count && data > ans) { //并列的情况 count = book[data]; ans = data; } } } cout << ans << " " << count; return 0; }
就是边读边判断 !!!
标签:data view cstring 分享图片 iostream its c++ opened bsp
原文地址:https://www.cnblogs.com/bxd123/p/10192955.html