#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
int N,M;
cin>>N>>M;
string *str = new string[M];
for(int i=0;i<M;i++)
cin>>str[i];
//转置字符串
vector<vector<char> > transStr(N,vector<char>(M));
for(int i=0;i<N;i++)
{
for(int j=0;j<M;j++)
{
transStr[i][j] = str[j][i];
}
}
//排序
for(int i=0;i<N;i++)
{
sort(transStr[i].begin(),transStr[i].end());
}
//每个字符串对应字符比较,并统计
vector<char> strTemp=transStr[0];
int index = -1;
for(int i=1;i<N;i++)
{
int count_0=0;
int count_m=0;
for(int j=0;j<M;j++)
{
if(strTemp[j]>transStr[i][j])
{
count_m++;
}
if(strTemp[j]<transStr[i][j])
{
count_0++;
}
}
if(count_0<count_m)
{
strTemp=transStr[i];
index = i;
}
else if(count_0<count_m)
index = 0;
else
index = -1;
}
cout<<index;
return 0;
}
2018.7.22拼多多笔试题2———谁是球王?
猜你喜欢
转载自blog.csdn.net/imprincess/article/details/81433556
今日推荐
周排行