65,186
社区成员




#include <algorithm>
class Coder {
public:
vector<string> findCoder(vector<string> &A, int n)
{
vector<string> result;
stable_sort(A.begin(),A.end(),compare_times);//报错:reference to non-static member function must be called
vector<string>::iterator p_Push=find_first(A);
while(p_Push<A.end())
{
result.push_back(*p_Push);
p_Push++;
}
return result;
}
bool compare_times(const string &a,const string &b)
{
return times(a)<times(b);
}
vector<string>::iterator find_first(vector<string> &A)
{
for(vector<string>::iterator pFirst=A.begin();pFirst!=A.end();pFirst++)
{
if(times(*pFirst)!=0)
return pFirst;
}
}
int times(string a,int currentIndex=0,int state=0)
{
if(currentIndex==a.size())
return 0;
switch (state)
{
case 0:
{
if(a[currentIndex]=='c'||a[currentIndex]=='C') return times(a,currentIndex+1,1);
else return times(a,currentIndex+1,0);
}
case 1:
{
if(a[currentIndex]=='o'||a[currentIndex]=='O') return times(a,currentIndex+1,2);
else return times(a,currentIndex+1,0);
}
case 2:
{
if(a[currentIndex]=='d'||a[currentIndex]=='D') return times(a,currentIndex+1,3);
else return times(a,currentIndex+1,0);
}
case 3:
{
if(a[currentIndex]=='e'||a[currentIndex]=='E') return times(a,currentIndex+1,4);
else return times(a,currentIndex+1,0);
}
default:
{
if(a[currentIndex]=='r'||a[currentIndex]=='R') return 1+times(a,currentIndex+1,0);
else return times(a,currentIndex+1,0);
}
}
}
};