这个题相对来书比较简单:只是一个数据的统计过程,怎样统计一组相同类型字符数组,我利用的是 vector<string> str;
#include "iostream"
#include "string"
#include "vector"
using namespace std;
int sort(string s, int _num)
{
char ch;
int count = 0;
for(int i = 0; i < _num; i++)
{
ch = s[i];
for(int j = i + 1; j < _num; j++ )
{
if(ch > s[j])
count++;
}
}
return count;
}
int main()
{
int num, length;
cin >> length >> num;
vector<string> str;
vector<int> sortNum;
for(int i = 0; i < num; i++)
{
string _str;
cin>>_str;
str.push_back(_str);
int _sortNum = 0;
_sortNum = sort(_str, length);
sortNum.push_back(_sortNum);
}
int _max = 0, i, j;
for(i = 0; i < num; i++)
{
for(j = i+1; j < num; j++)
{
if(sortNum[i] > sortNum[j])
{
_max = sortNum[i];
sortNum[i] = sortNum[j];
sortNum[j] = _max;
string strEx = str[i];
str[i] = str[j];
str[j] = strEx;
}
}
cout << str[i] << endl;
}
return 0;
}