📄 3026731_ac_15ms_248k.cpp
字号:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
using namespace std;
class Node
{
private:
string m_str;
int m_sorted;
public:
Node(string str=NULL,int s=0):m_str(str),m_sorted(s){}
string getm_str(void){return m_str;}
int getm_sorted(void){return m_sorted;}
};
inline bool less1(Node node1,Node node2)
{
if(node1.getm_sorted()<=node2.getm_sorted())
return true;
return false;
}
int calculateSorted(string );
int main()
{
int length,number,i=0;
string tempStr;
cin>>length>>number;
vector<string> pStr;
vector<Node> NodeStore;
while(i!=number)
{
cin>>tempStr;
pStr.push_back(tempStr);
i++;
}
for(i=0;i!=number;i++)
{
NodeStore.push_back(Node(pStr[i],calculateSorted(pStr[i])));
}
sort(NodeStore.begin(),NodeStore.end(),less1);
for(i=0;i!=number;i++)
{
cout<<NodeStore[i].getm_str()<<endl;
}
return 0;
}
int calculateSorted(string str)
{
int result=0,i,j;
for(i=0;i<str.length();i++)
{
for(j=i+1;j<str.length();j++)
{
if(str[i]>str[j])
result++;
}
}
return result;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -