c++结构体数组的应用

以下分析根据来源:题目poj 1007 

https://cn.vjudge.net/problem/POJ-1007

#include
#include
using namespace std;
struct tag{
	char s1[55];
	int a;
};
bool compare(tag x,tag y)
{
	return x.a>n>>m;
	for(int i=0;i>mysort[i].s1;
		mysort[i].a=0;
	}
	for(int i=0;imysort[i].s1[h])
				{
					mysort[i].a++;
				}
			}
		}
	}
	sort(mysort,mysort+m,compare);
	for(int i=0;i

题目思路:

对m组字符串排序,其排序根据是字符串反序的数目

解题思路:

设一个大小为m的字符串结构体,用结构体存该字符串以及反序数。

struct stg{

char str[103];

int a;

}mysort[54];

然后利用for循环求出反序数

之后利用反序数进行排序

sort(mysort,mysort+m,compare);

bool compare(tag x,tag y)

{

return x.a

}

排序后输出字符串结束

你可能感兴趣的:(c++结构体数组的应用)