题目链接
http://acm.hdu.edu.cn/showproblem.php?pid=1084
题目有一个细节要注意,就是当有个人做的题相同时有n/2的人要多五分;例如有5个人做三题那么1个人85,另外两个人80风
#include<stdio.h>
#include<string.h>
int main()
{
int n,d,k,i,j,g1;
int p[105];
char t1[120][20];
while(scanf("%d",&n)==1&&n>=0)
{
for(i=0;i<n;i++)
{
scanf("%d%s",&p[i],t1[i]);
}
for(i=0;i<n;i++)
{
switch(p[i])
{
case 5: d=100;break;
case 4: d=95; break;
case 3: d=85; break;
case 2: d=75; break;
case 1: d=65; break;
case 0: d=50; break;
}
k=0;
if(p[i]>=1&&p[i]<=4)
{
for(j=0;j<n;j++)
{
if(p[j]==p[i])
k++;
}
if(k>1)
{
g1=1;
for(j=0;j<n;j++)
{
if(j==i)
continue;
if(p[i]==p[j])
{
if(strcmp(t1[i],t1[j])>0)
g1++;
}
}
if(g1*2>k)
d=d-5;
}
}
printf("%d
",d);
}
printf("
");
}
return 0;
}
其他写法
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
struct ssss
{
int number,time,much;
}ss[111];
bool cmp(const ssss &a,const ssss &b)
{
if(a.number>b.number||a.number==b.number&&a.time<b.time)return 1;
return 0;
}
int main (void)
{
int n,i,j,k,l,hash1[111],hash2[111],a,b,c;
while(cin>>n&&n>=0)
{
if(!n)continue;
for(i=0;i<111;i++)hash1[i]=hash2[i]=0;
for(i=0;i<n;i++)
{
scanf("%d%d:%d:%d",&ss[i].number,&a,&b,&c);
ss[i].time=a*3600+b*60+c;
ss[i].much=i+1;
hash1[ss[i].number]++;
}
sort(ss,ss+n,cmp);
for(i=0;i<n;i++)
{
if(!i)l=ss[i].number,j=hash1[l]/2;
if(ss[i].number<l)
l=ss[i].number,j=hash1[l]/2;
a=ss[i].number*10+50;
hash2[ss[i].much]=a;
if(a!=100&&j-->0)hash2[ss[i].much]+=5;
if(ss[i].number==0)hash2[ss[i].much]=50;
}
for(i=1;i<=n;i++)
cout<<hash2[i]<<endl;
cout<<endl;
}
return 0;
}