CodeForces 19A World Football Cup (简单题)
来源:互联网 发布:node fetch 编辑:程序博客网 时间:2024/05/17 04:21
题目类型 简单题
题目意思
输入 n (1 <= n <=50, 且 n 为偶数) 支足球队的队名和各个队与其他队比赛一场后的比分, 按字典序输出最终排在前面 n / 2支队的队名
排名首先看得分情况 (比赛结果中 赢的一方得3分 输的一方得0分 | 平手情况两队各得一分)
如果得分相同就看 (进球数 - 失球数) 的值, 如果还是相同就看进球数 (都是大的排在前面)
解题方法
成功输入数据后, 统计数据, 最后排序输出即可 (详情看代码)
附 :
STL(98) 在 ACM 中的应用 还没了解的同学都看下 -> 中文简洁版 | STL in ACM | 英文完全版第一部分 英文完全版第二部分
参考代码 - 有疑问的地方在下方留言 看到会尽快回复的
#include <iostream>#include <cstdio>#include <cstring>#include <map>#include <set>#include <algorithm>using namespace std;char str[100][100];char s[100];char s1[100], s2[100];struct P { string name; int s; int w, l;}p[110];bool cmp(const P & a, const P & b ) { if(a.s == b.s) { if(a.w - a.l == b.w - b.l) { return a.w > b.w; } else return a.w - a.l > b.w - b.l; } return a.s > b.s;}bool cmp2(const P & a, const P & b) { return a.name < b.name;}int main() { int n, a, b; while(scanf("%d", &n) != EOF) { map<string,int>mm; map<string,int>w; map<string,int>l; set<string>name; set<string>::iterator ps; for( int i=0; i<n; i++ ) { scanf("%s", str[i]); } for( int i=0; i<n*(n-1)/2; i++ ) { scanf("%s", s); int len = strlen(s), k1 = 0, k2 = 0; bool f = 0; for( int i=0; i<len; i++ ) { if(s[i] == '-') { f = 1; continue; } if(f) s2[k2++] = s[i]; else s1[k1++] = s[i]; } s1[k1] = '\0', s2[k2] = '\0'; scanf("%d:%d", &a, &b); string ts1 = s1; string ts2 = s2; if(name.find(ts1) == name.end()) name.insert(ts1); if(name.find(ts2) == name.end()) name.insert(ts2); w[ts1] += a; l[ts1] += b; w[ts2] += b; l[ts2] += a; if(a > b) mm[ts1] += 3; else if(a == b) mm[ts1]++, mm[ts2]++; else mm[ts2] += 3; } int k = 0; for( ps=name.begin(); ps != name.end(); ps++ ) { p[k].name = *ps; p[k].s = mm[*ps]; p[k].w = w[*ps]; p[k].l = l[*ps]; k++; } sort(p, p + k, cmp); sort(p, p + n/2, cmp2); for( int i=0; i<n/2; i++ ) cout<<p[i].name<<endl; } return 0;}
0 0
- CodeForces 19A World Football Cup (简单题)
- Codeforces 19A World Football Cup 【模拟】
- CodeForces 19A World Football Cup
- CodeForces 19A World Football Cup (水题)
- A. World Football Cup
- CF 19A World Football Cup
- 【map+审题】#19 A. World Football Cup
- cf 19a World Football Cup
- CodeForce 19A World Football Cup (string类应用)
- CF World Football Cup
- 【多过程模拟】CodeForce 19A——World Football Cup
- 19AWorld Football Cup
- cf19A World Football Cup (排序)
- CodeForces-96A-Football
- Codeforces 43 A. Football
- 【CodeForces】A. Football
- CodeForces 96A Football
- codeforces 43A Football
- C#-二维数组---ShinePans
- Leetcode: Add Binary 理解分析
- poj Common Subsequence 最长公共子序列
- 居中显示的Toast
- ofbiz 权限设计及动态二级菜单解决方案
- CodeForces 19A World Football Cup (简单题)
- [Flight] Pitch Yaw Roll的区别
- jsp里用Ajax做的select的两级级联
- mysql 时间函数总结
- 好用的网站
- DIV+CSS的命名规则
- 关于android安卓的静态数据库文件的存取问题
- 基于can总线节点ECU的设计
- The interface EntityDao cannot be implemented more than once with different arguments: EntityDao<Sit