NOJ1023 字符串排序

和以往不同,这次尤为严重,在理解题意方面。关于此方面我觉得我真的十分对不起我所有的语文老师(误…

对所有输入的数据,先按字符A的个数进行升序排序,如果字符A的数量相等,再按出现的先后顺序排序,每行输出一个字符串 ——是按字符串出现的顺序排序

 include<iostream>
include<vector>
include<string>
include<algortihm>

using namespace std;
struct CC {
string str;
int firstposition=0;
int amount=0;
void countA();
void positionA();
bool operator<(const CC& A) const
{
if (amount < A.amount)
return true;
else
return false;
}
};
void CC::countA()
{ int amount = 0; for (auto t : this->str)
if (t == 'A')
amount++;
this->amount = amount;
}
void CC::positionA()
{
int i = 0;
for (; i != (this->str).size(); i++)
if (str[i] == 'A')
this->firstposition = i;
}
void print_each(const CC& c)
{
cout << c.str << endl;
}

int main()
{ vector list;
CC temp;
while (cin >> temp.str)
{
temp.countA();
temp.positionA();
list.push_back(temp);
}
sort(list.begin(), list.end());
for_each(list.begin(), list.end(), print_each);
return 0;
}

NOJ1023 字符串排序》有1个想法

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注