Description:
有一些A、C、M组成的字符串,将其按字符A排序。
Input:
一组测试数据,输入数据由若干行组成,每行是字符A、C或M组成的字符串。(每个字符串长度不超过1200)
Output:
对所有输入的数据,先按字符A的个数进行升序排序,如果字符A的数量相等,再按出现的先后顺序排序,每行输出一个字符串。
Sample Input:
ACM
MCA
AACAAMMM
AACCMM
CMAAMMMMMM
AAA
Sample Output:
ACM
MCA
AACCMM
CMAAMMMMMM
AAA
AACAAMMM
Note:
本题由旧版NOJ导入,来源:NUPT
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <climits>
#include <stdio.h>
#include <iomanip>
#include <math.h>
#include <list>
#include <queue>
#include <tuple>
#include <stack>
#include <string.h>
using namespace std;
typedef struct
{
string name;
long long index;
}mystruct;
bool mycmp(const mystruct& A, const mystruct& B)
{
long long countA = 0;
long long countB = 0;
for(int i = 0; i < A.name.size(); i++)
{
if(A.name[i] == 'A')
countA++;
}
for(int i = 0; i < B.name.size(); i++)
{
if(B.name[i] == 'A')
countB++;
}
if(countA < countB)
return true;
else if(countA > countB)
return false;
if(A.index < B.index)
return true;
return false;
}
int main(void)
{
vector<mystruct> nums;
string tmp;
long long id = 0;
while(cin >> tmp)
{
mystruct tmp1;
tmp1.name = tmp;
tmp1.index = id;
nums.push_back(tmp1);
id++;
}
sort(nums.begin(), nums.end(), mycmp);
for(int i = 0; i < nums.size(); i++)
{
cout << nums[i].name<<endl;
}
return 0;
}