排序,结构体排序,大小排序
Problem F
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 3 Accepted Submission(s) : 2
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Input
Output
Sample Input
4 5 06:30:17 4 07:31:27 4 08:12:12 4 05:23:13 1 5 06:30:17 -1
Sample Output
100 90 90 95 100
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
char a[100][9];
int b[100],c[100],d[6],N,i,j,f;
while(cin>>N)
if(N>-1)
{
memset(d,0,sizeof(d));
for(i=0;i<N;i++)
{cin>>b[i]>>a[i];
switch(b[i])
{
case 5:d[5]++;break;
case 4:d[4]++;break;
case 3:d[3]++;break;
case 2:d[2]++;break;
case 1:d[1]++;break;
}
memset(c,0,sizeof(c));
}
for(i=0;i<N;i++)
for(int j=0;j<N;j++)
if(strcmp(a[i],a[j])>0&&b[i]==b[j])c[i]++;
for(i=0;i<N;i++)
{
switch(b[i])
{
case 5:cout<<100<<endl;break;
case 4:if(c[i]<d[4]/2)cout<<95<<endl;
else cout<<90<<endl;break;
case 3:if(c[i]<d[3]/2)cout<<85<<endl;
else cout<<80<<endl;break;
case 2:if(c[i]<d[2]/2)cout<<75<<endl;
else cout<<70<<endl;break;
case 1:if(c[i]<d[1]/2)cout<<65<<endl;
else cout<<60<<endl;break;
default:cout<<50<<endl;break;
}
}
cout<<endl;
}
return 0;
}
我写的
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std
; int main()
{
int t,save[6][2]={50,50,60,65,70,75,80,85,90,95,100,100},j,i,h,g,temp[100],a1[100],a[100],ans[1000],k;
char c[100][1000];
while(scanf("%d",&t))
{
if(t<=0)
break;
memset(a1,0,sizeof(a1));
memset(temp,0,sizeof(temp));
for(h=0;h<t;h++)
{
scanf("%d",&a[h]);
j=a[h];
a1[j]++;
cin>>c[h];
}
for(i=0;i<t;i++)
for(g=0;g<t;g++)
if(strcmp(c[i],c[g])>0&&a[i]==a[g])temp[i]++;
for(i=0;i<t;i++)
{
k=a[i];
if(temp[i]<a1[k]/2)
ans[i]=save[k][1];
else
ans[i]=save[k][0];
}
for(i=0;i<t;i++)
cout<<ans[i]<<endl;
cout<<endl;
}
return 0;
}
#include <iostream>
#include <stdio.h>
#include<string.h>
#include <algorithm>
using namespace std;
struct node {
int index; int score; int p,t;
bool operator<(const node&a)const;
};node a[103];
bool node:: operator<(const node&b)const
{ if(b.p==p) return t<b.t; return p>b.p; }
bool cmp1(const node&a,const node&b)
{ return a.index<b.index;
} int hash[6];
int main() {
int i,j,n;
int h,m,s;
while(scanf("%d",&n),n!=-1)
{
memset(hash,0,sizeof(hash));
for(i=0;i<n;i++)
{
scanf("%d %d:%d:%d",&a[i].p,&h,&m,&s);
hash[a[i].p]++;
a[i].t=h*3600+m*60+s;
a[i].index=i;
}
sort(a,a+n);
i=0;
while(a[i].p==5)
a[i++].score=100;
for(j=0;j<hash[4]/2;j++)
a[i++].score=95;
for(;j<hash[4];j++)
a[i++].score=90;
for(j=0;j<hash[3]/2;j++)
a[i++].score=85;
for(;j<hash[3];j++)
a[i++].score=80;
for(j=0;j<hash[2]/2;j++)
a[i++].score=75;
for(;j<hash[2];j++)
a[i++].score=70;
for(j=0;j<hash[1]/2;j++)
a[i++].score=65;
for(;j<hash[1];j++)
a[i++].score=60;
for(;i<n;i++)
a[i].score=50;
sort(a,a+n,cmp1);
for(i=0;i<n;i++)
printf("%d\n",a[i].score);
printf("\n");
}
return 0;
}