class Result_to_user {
public:
    string s_value[10];
	int    int_value[10];
	static int    member_count;
	static int    isString[20];
} ;
 int Result_to_user::member_count=0;
  int    Result_to_user::isString[20];

#define CMP_RESULT_TO_USER(i) bool cmp_result_to_user_string_##i (const Result_to_user&v1,const Result_to_user&v2) \
{return v1.s_value[##i]< v2.s_value[##i];}

#define CMP_RESULT_TO_USER_INT(i) bool cmp_result_to_user_int_##i (const Result_to_user&v1,const Result_to_user&v2) \
{return v1.int_value[##i]< v2.int_value[##i];}


CMP_RESULT_TO_USER(0)
CMP_RESULT_TO_USER(1)
CMP_RESULT_TO_USER(2)
CMP_RESULT_TO_USER(3)
CMP_RESULT_TO_USER(4)
CMP_RESULT_TO_USER(5)
CMP_RESULT_TO_USER(6)
CMP_RESULT_TO_USER(7)
CMP_RESULT_TO_USER(8)
CMP_RESULT_TO_USER(9)

CMP_RESULT_TO_USER_INT(0)
CMP_RESULT_TO_USER_INT(1)
CMP_RESULT_TO_USER_INT(2)
CMP_RESULT_TO_USER_INT(3)
CMP_RESULT_TO_USER_INT(4)
CMP_RESULT_TO_USER_INT(5)
CMP_RESULT_TO_USER_INT(6)
CMP_RESULT_TO_USER_INT(7)
CMP_RESULT_TO_USER_INT(8)
CMP_RESULT_TO_USER_INT(9)

#define CMP_REULT(i) cmp_result_to_user_string_##i
#define CMP_REULT_INT(i) cmp_result_to_user_int_##i

bool (*cmp_result_string[20])(const Result_to_user&v1,const Result_to_user&v2)=
{
	CMP_REULT(0),CMP_REULT(1),CMP_REULT(2),CMP_REULT(3),CMP_REULT(4),CMP_REULT(5),CMP_REULT(6),CMP_REULT(7),CMP_REULT(8),CMP_REULT(9),
	CMP_REULT_INT(0),CMP_REULT_INT(1),CMP_REULT_INT(2),CMP_REULT_INT(3),CMP_REULT_INT(4),CMP_REULT_INT(5),CMP_REULT_INT(6),CMP_REULT_INT(7),CMP_REULT_INT(8),CMP_REULT_INT(9)
};

static int    member_count;
static int    isString[20];


// from 0
 bool (*  find_cmp(int n))(const Result_to_user&v1,const Result_to_user&v2)
 {
	 int re;
	 int i;
	 if (Result_to_user::isString[n]==1)
	 {
		 re=0;
		 for (i=0;i<n;i++)
		 {
			 if (Result_to_user::isString[i])
			 {
				 re++;
			 }			 
		 }
	 }
	 else
	 {
		 re=10;
		 for (i=0;i<n;i++)
		 {
			 if (Result_to_user::isString[i]==0)
			 {
				 re++;
			 }			 
		 }
	 }
	 return cmp_result_string[re];
 }
 
 int find_pos_string(int n)// from 0 to 20

 {
	 int re;
	 int i;

	 re=-1;
	 for (i=0;i<=n;i++)
	 {
		 if (Result_to_user::isString[i])
		 {
			 re++;
		 }			 
	 }

	 return re;
 }
 int find_pos_int(int n)// from 0 to 20

 {
	 int re;
	 int i;
	  
		 re=-1;
		 for (i=0;i<=n;i++)
		 {
			 if (Result_to_user::isString[i]==0)
			 {
				 re++;
			 }			 
		 }
	 
	 return re;
 }
int ssss()
{
	vector<Result_to_user> v;
	int i;

    Result_to_user r[10];
	r[0].s_value[0]="df";
	r[1].s_value[0]="gg";
	r[2].s_value[0]="fdd";
	r[3].s_value[0]="ddgd";

	r[0].int_value[0]=123;
	r[1].int_value[0]=45;
	r[2].int_value[0]=4532;
	r[3].int_value[0]=23344;


	


	r[0].int_value[1]=6345;
	r[1].int_value[1]=345634;
	r[2].int_value[1]=234;
	r[3].int_value[1]=2345;

	r[0].s_value[1]="e";
	r[1].s_value[1]="c";
	r[2].s_value[1]="b";
	r[3].s_value[1]="a";

	Result_to_user::isString[0]=1;
	Result_to_user::isString[1]=0;
	Result_to_user::isString[2]=0;
	Result_to_user::isString[3]=1;
	Result_to_user::member_count=4;

	v.push_back(r[0]);
	v.push_back(r[1]);
	v.push_back(r[2]);
	v.push_back(r[3]);

	sort(v.begin(),v.end(),find_cmp(0));

	for ( i=0;i<4;i++)
	{
		cout<<v[i].s_value[find_pos_string(0)]<<"  "<<v[i].int_value[find_pos_int(1)]<<" "<<v[i].int_value[find_pos_int(2)]<<"  "<<v[i].s_value[find_pos_string(3)]<<endl;
	}

 
	cout<<endl;

	sort(v.begin(),v.end(),find_cmp(1));

	for ( i=0;i<4;i++)
	{
		cout<<v[i].s_value[find_pos_string(0)]<<"  "<<v[i].int_value[find_pos_int(1)]<<" "<<v[i].int_value[find_pos_int(2)]<<"  "<<v[i].s_value[find_pos_string(3)]<<endl;

	}


	cout<<endl;
	sort(v.begin(),v.end(),find_cmp(2));

	for ( i=0;i<4;i++)
	{
		cout<<v[i].s_value[find_pos_string(0)]<<"  "<<v[i].int_value[find_pos_int(1)]<<" "<<v[i].int_value[find_pos_int(2)]<<"  "<<v[i].s_value[find_pos_string(3)]<<endl;

	}


	cout<<endl;
	sort(v.begin(),v.begin()+2,find_cmp(3));

	for ( i=0;i<4;i++)
	{
		cout<<v[i].s_value[find_pos_string(0)]<<"  "<<v[i].int_value[find_pos_int(1)]<<" "<<v[i].int_value[find_pos_int(2)]<<"  "<<v[i].s_value[find_pos_string(3)]<<endl;
	}


	cout<<endl;
	 

    return 0;
}

 

posted on 2013-09-13 22:30  宇睿  阅读(222)  评论(0编辑  收藏  举报