栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 2443 Easy Task

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 2443 Easy Task

#include <ctype.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#define char2int(ch) ((isdigit(ch))?(ch-'0'+26):(ch-'a'))struct Prob{    char ac;    int sub;    int time;};struct Prob p[9];void show(char prob,struct Prob *p){    putchar(prob);    if(p->ac) printf(" %d %.2lf %.2lfn",p->ac,(double)p->sub/p->ac,(double)p->time/p->ac);    else printf(" 0n");}struct Team{    struct Prob p[9];};struct Team t[2000];struct Trie{    int mark;    struct Trie *p[36];};struct Trie root;int size;void init(struct Trie *p){    int i;    p->mark=-1;    for(i=0;i<36;i++)        p->p[i]=NULL;}void clear(struct Trie *p){    int i;    for(i=0;i<36;i++){        if(p->p[i]==NULL) continue;        else{ clear(p->p[i]); free(p->p[i]);        }    }}int find(struct Trie *t,char *p){    int next=char2int(*p);    if(*p==''){        if(t->mark!=-1) return t->mark;        else return t->mark=size++;    }    else{        if(t->p[next]==NULL) init(t->p[next]=(struct Trie*)malloc(sizeof(struct Trie)));        return find(t->p[next],p+1);    }}void doit(int time,char *team,char prob,char ac){    int tid=find(&root,team);    int pid=prob-'A';    if(t[tid].p[pid].ac) return;    t[tid].p[pid].sub++;    if(ac=='A'){        t[tid].p[pid].ac=1;        p[pid].ac++;        p[pid].sub+=t[tid].p[pid].sub;        p[pid].time+=time;    }}int main(){    int blank=0,i,n,time;    char team[6],prob[3],res[3];    while(scanf("%d",&n)!=EOF){        if(blank) putchar('n');        else blank=1;        memset(p,0,sizeof(p));        memset(t,0,sizeof(t));        size=0;        init(&root);        for(i=0;i<n;i++){ scanf("%d%s%s%s",&time,team,prob,res); doit(time,team,*prob,*res);        }        clear(&root);        for(i=0;i<9;i++) show('A'+i,&p[i]);    }    return 0;   }
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/369927.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号