国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

HDU 杭電 acm-2093-考試排名

2019-11-11 07:31:59
字體:
供稿:網(wǎng)友

題目地址:http://acm.hdu.edu.cn/showPRoblem.php?pid=2093

/************************************************************************

這題廢了一番功夫。。

首先題目沒給出人數(shù),乍一看懵了。參考了網(wǎng)上的代碼,用 while(scanf("%s",name)!=EOF)來結(jié)束人的輸入,鍵盤同時按住ctrl+z,輸入文件結(jié)束符,再回車,計算排名。同時把存儲人的數(shù)組定義的大一點(diǎn)(10000為例);

其次是數(shù)據(jù)的輸入竟然還有括號,原想用getchar()來接收并檢測是不是括號,但容易出錯,干脆全部用%s接收成字符串,再寫個函數(shù)轉(zhuǎn)化為純數(shù)字。

/****************************************************************************************

代碼如下:

/*************************

#include<stdio.h>#include<stdlib.h>#include<string.h>#include<algorithm>using namespace std;struct person{    char name[11];    int accepted;    int punish;}acmer[10000];int n,m;//n題目數(shù),m懲罰分 int cmp(const void *q,const void *w){    person *a=(person*)q,*b=(person*)w;        if(a->accepted!=b->accepted)        return b->accepted-a->accepted;    if(a->punish!=b->punish)        return a->punish-b->punish;    return strcmp(a->name,b->name);}int to_int(char *p)//此函數(shù)將字符串中的數(shù)字轉(zhuǎn)化為int型數(shù)據(jù) {    if(*p=='-'||*p=='0')        return 0;//題目沒做對,不做統(tǒng)計,直接0     int punish=0,temp=0;    while(*p)    {        if(*p=='(')        {            while(*(++p)!=')')            {                temp=temp*10+*p-'0';            }            break;        }        punish=punish*10+*p-'0';        p++;    }    return punish+temp*m;}int main(){    char a[12];    int score,i=0;    scanf("%d%d",&n,&m);    while(scanf("%s",acmer[i].name)!=EOF)    {        acmer[i].accepted=0;        acmer[i].punish=0;        for(int j=0;j<n;j++)        {            scanf("%s",a);            score=to_int(a);            if(score>0)            {                acmer[i].accepted++;                acmer[i].punish+=score;            }        }        i++;    }        qsort(acmer,i,sizeof(acmer[0]),cmp);    for(int j=0;j<i;j++)    {        printf("%-10s %2d %4d/n",acmer[j].name,acmer[j].accepted,acmer[j].punish);    }    return 0;}


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 玛曲县| 墨江| 湖北省| 微山县| 迁西县| 沭阳县| SHOW| 永顺县| 清水河县| 兴海县| 石景山区| 高尔夫| 河北区| 农安县| 郸城县| 万盛区| 保亭| 彩票| 额济纳旗| 内江市| 和平县| 蕲春县| 吴江市| 阿鲁科尔沁旗| 凤冈县| 绥阳县| 大丰市| 兰州市| 沾化县| 华坪县| 满洲里市| 毕节市| 腾冲县| 宁波市| 中山市| 玛多县| 册亨县| 金寨县| 库伦旗| 阿巴嘎旗| 清镇市|