新年快乐!!!
今天主要是排序题。
题目很水,数据很弱,本人很菜。
#include
#include
#include
using namespace std;
int n, k;
struct student{
int num;
double score;
}st[105];
bool cmp(student x, student y)
{
return x.score>y.score;
}
int main()
{
scanf("%d%d", &n, &k);
for(int i=1; i<=n; i++)
scanf("%d%lf", &st[i].num, &st[i].score);
sort(st+1, st+n+1, cmp);
printf("%d %g", st[k].num, st[k].score);
return 0;
}
#include
using namespace std;
int n, x, a[505], tot=0;
int main()
{
cin>>n;
for(int i=1; i<=n; i++)
{
cin>>x;
if(x%2) a[tot++] = x;
}
sort(a, a+tot);
for(int i=0; i<tot-1; i++)
printf("%d,", a[i]);
printf("%d", a[tot-1]);
return 0;
}
#include
using namespace std;
struct node{
string name;
int score;
}st[25];
bool comp(node x, node y)
{
if(x.score != y.score) return x.score>y.score;
else return x.name<y.name;
}
int main()
{
int n;
while(cin>>n)
{
for(int i=1; i<=n; i++)
{
cin>>st[i].name;
scanf("%d", &st[i].score);
}
sort(st+1, st+n+1, comp);
for(int i=1; i<=n; i++)
{
cout<<st[i].name<<" ";
printf("%d\n", st[i].score);
}
}
return 0;
}
#include
using namespace std;
int main()
{
int n, k, a[1050], cnt=0;
while(cin>>n>>k)
{
cnt = 0;
for(int i=1; i<=n; i++)
cin>>a[i];
sort(a+1, a+1+n);
reverse(a+1, a+1+n);
for(int i=1; i<=k; i++)
cnt+=a[i];
printf("%d\n", cnt);
}
return 0;
}
#include
using namespace std;
int n, k, x, cnt=0, maxn=-1;
int a[100010];
int main()
{
while(scanf("%d%d", &n, &k) != EOF)
{
cnt=0, maxn=-1;
memset(a, 0, sizeof(a));
for(int i=1; i<=n; i++)
{
scanf("%d", &x);
a[x]++;
maxn = max(maxn, x);
}
int i=maxn;
while(k)
{
if(!a[i])
{
i--;
continue;
}
else
{
if(k>=a[i])
{
cnt += i*a[i];
k -= a[i];
i--;
}
else
{
cnt += i*k;
k=0;
}
}
}
printf("%d\n", cnt);
}
return 0;
}
#include
using namespace std;
struct node{
int a, b, c, d, flag, cnt;
}sc[105];
int n;
bool comp(node x, node y)
{
if(x.cnt != y.cnt) return x.cnt>y.cnt;
else
{
if(x.a != y.a) return x.a>y.a;
else
{
if(x.b != y.b) return x.b>y.b;
else
{
if(x.c != y.c) return x.c>y.c;
else return x.d>y.d;
}
}
}
}
int main()
{
while(cin>>n)
{
for(int i=1; i<=n; i++)
{
cin>>sc[i].a>>sc[i].b>>sc[i].c>>sc[i].d;
sc[i].cnt = sc[i].a+sc[i].b+sc[i].c+sc[i].d;
sc[i].flag = i;
}
sort(sc+1, sc+n+1, comp);
for(int i=1; i<=n; i++)
printf("%d %d\n", sc[i].flag, sc[i].cnt);
}
return 0;
}
#include
using namespace std;
struct stu{
char name[105];
int sc;
}st[1050];
int n, m, o;
bool comp(stu x, stu y)
{
return x.sc>y.sc;
}
int main()
{
while(scanf("%d%d%d", &n, &m, &o) != EOF)
{
for(int i=1; i<=n; i++)
scanf("%s%d", st[i].name, &st[i].sc);
sort(st+1, st+n+1, comp);
for(int i=m; i>=1; i--)
printf("%s\n", st[i].name);
for(int i=n; i>=n-o+1; i--)
printf("%s\n", st[i].name);
}
return 0;
}
#include
using namespace std;
struct node{
int zy, dy, wy;
double z, d, w;
double quan;
char name[25];
} hero[100100];
bool comp(node x, node y)
{
if(x.quan != y.quan) return x.quan>y.quan;
else
{
if(x.z != y.z) return x.z>y.z;
else
{
if(x.d != y.d) return x.d>y.d;
else return x.w>y.w;
}
}
}
int t, n;
double a, b, c;
int main()
{
while(scanf("%d", &t) != EOF)
{
int flag = t;
while(t)
{
scanf("%d%lf%lf%lf", &n, &a, &b, &c);
for(int i=1; i<=n; i++)
{
scanf("%s%d%d%d", hero[i].name, &hero[i].zy, &hero[i].dy, &hero[i].wy);
hero[i].z = hero[i].zy*1.0*b/100;
hero[i].d = hero[i].dy*1.0*a/100;
hero[i].w = hero[i].wy*1.0*c/100;
hero[i].quan = hero[i].z+hero[i].d+hero[i].w;
}
sort(hero+1, hero+1+n, comp);
printf("Case #%d:\n", flag-t+1);
for(int i=1; i<=n; i++)
printf("%s %.4lf %.4lf %.4lf %.4lf\n", hero[i].name, hero[i].quan, hero[i].z, hero[i].d, hero[i].w);
t--;
}
}
return 0;
}
#include
using namespace std;
struct node{
char team[15];
int at, bt, ct;
int aw, bw, cw;
int tot, cnt;
}com[100100];
bool comp(node x, node y)
{
return x.tot<y.tot;
}
int main()
{
int n;
while(cin>>n)
{
for(int i=1; i<=n; i++)
scanf("%s%d%d%d", com[i].team, &com[i].at, &com[i].bt, &com[i].ct);
for(int i=1; i<=n; i++)
{
scanf("%d%d%d", &com[i].aw, &com[i].bw, &com[i].cw);
com[i].cnt=0;
com[i].tot=0;
}
for(int i=1; i<=n; i++)
{
if(com[i].at != -1)
{
com[i].cnt++;
com[i].tot += com[i].at + (com[i].aw-1)*20;
}
if(com[i].bt != -1)
{
com[i].cnt++;
com[i].tot += com[i].bt + (com[i].bw-1)*20;
}
if(com[i].ct != -1)
{
com[i].cnt++;
com[i].tot += com[i].ct + (com[i].cw-1)*20;
}
}
sort(com+1, com+n+1, comp);
for(int i=1; i<=n; i++)
printf("%s %d %d\n", com[i].team, com[i].cnt, com[i].tot);
}
return 0;
}
#include
using namespace std;
struct point{
int x, y;
}p[1050];
bool cmp00(point a, point b)
{
if(a.x!=b.x) return a.x>b.x;
else return a.y>b.y;
}
bool cmp01(point a, point b)
{
if(a.x!=b.x) return a.x>b.x;
else return a.y<b.y;
}
bool cmp10(point a, point b)
{
if(a.x!=b.x) return a.x<b.x;
else return a.y>b.y;
}
bool cmp11(point a, point b)
{
if(a.x!=b.x) return a.x<b.x;
else return a.y<b.y;
}
int main()
{
int L, R, n;
while(cin>>L>>R>>n)
{
for(int i=1; i<=n; i++)
cin>>p[i].x>>p[i].y;
if(!L)
{
if(!R) sort(p+1, p+n+1, cmp00);
else sort(p+1, p+n+1, cmp01);
}
else
{
if(!R) sort(p+1, p+n+1, cmp10);
else sort(p+1, p+n+1, cmp11);
}
for(int i=1; i<=n; i++)
cout<<"("<<p[i].x<<","<<p[i].y<<")"<<endl;
}
return 0;
}