zoukankan      html  css  js  c++  java
  • qsort 结构体二级排序实例

    题目链接 ——〉http://acm.nefu.edu.cn/JudgeOnline/problem/137.jsp

    #include<iostream>
    #include
    <stdlib.h>
    using namespace std;
    struct Url{
        
    int no, rel ;
        
    string url ;
    }page[
    10] ;

    int cmp(const void *a, const void *b){          //rel从大到小,no从小到大
        
    struct Url *= (Url *)a ;
        
    struct Url *= (Url *)b ;
        
    if(c->rel!=d->rel)  return d->rel - c->rel ;
        
    else    return c->no - d->no ;
    }
    int main(){
        
    int n, j=0;
        cin 
    >> n ;
        
    while(n--){
            j 
    ++ ;
            
    for(int i=0; i<10; i++){
                cin 
    >> page[i].url >> page[i].rel ;
                page[i].no 
    = i ;
            }
            qsort(page, 
    10sizeof(page[0]), cmp) ;
            cout 
    << "Case #" << j << ":" << endl ;
            
    for(int i=0; i<10; i++){
                cout 
    << page[i].url << endl ;
                
    if(page[i].rel!=page[i+1].rel)  break ;
            }
        }
        
    return 0 ;
    }
  • 相关阅读:
    jQuery中的表单验证
    使用jQuery操作DOM对象
    jQuery中的事件和动画
    jQuery的选择器
    divise
    Word History airplay
    a前缀
    con词根
    vert词根
    quest词根
  • 原文地址:https://www.cnblogs.com/xiaolongchase/p/2154731.html
Copyright © 2011-2022 走看看