Official
C - Most Minority Editorial by en_translator
This problem asks to do the following:
- Temporarily memorize all the votes.
- For each vote round, determine who got the scores, and find the total score of each person.
- Find all people with the highest score.
This procedure can be implemented with a for statement.
Sample code (C++):
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,m;
cin >> n >> m;
vector<string> s(n);
for(auto &nx : s){cin >> nx;}
vector<int> pt(n,0);
for(int j=0;j<m;j++){
int x=0,y=0;
for(int i=0;i<n;i++){
if(s[i][j]=='0'){x++;}
else{y++;}
}
for(int i=0;i<n;i++){
if(s[i][j]=='0'){
if(x<=y){pt[i]++;}
}
else{
if(x>=y){pt[i]++;}
}
}
}
int high=(*max_element(pt.begin(),pt.end()));
bool spc=false;
for(int i=0;i<n;i++){
if(pt[i]==high){
if(spc){cout << " ";}
cout << i+1;
spc=true;
}
}cout << "\n";
return 0;
}
posted:
last update: