小编Căt*_*ală的帖子

在C++中对结构的向量进行排序

我有个问题.声明说,比赛的结果是从标准输入中读取的,我必须按照已解决问题的数量按顺序在屏幕上打印最终排名.这是我的代码.

#include <cstdio>
#include <vector>
#include <cstdlib>
using namespace std;

struct results
{
  unsigned int id; //id of the team
  unsigned int m; //number of solved problems
};

int comparare(const void * i, const void * j) //compare function for qsort()
{
  return -( *(unsigned int*)i - *(unsigned int*)j );
}

int main()
{

  unsigned int n;
  vector<results> standings; //initializing an array of structs

  scanf("%u", &n); //the size of the vector
  for(unsigned int i=0; i<n; ++i)
  {
    scanf("%u%u", &standings[i].id, &standings[i].m); …
Run Code Online (Sandbox Code Playgroud)

c++ struct qsort

0
推荐指数
1
解决办法
1192
查看次数

标签 统计

c++ ×1

qsort ×1

struct ×1