本地调试完全没问题,但在赛码上就是0%;
#include<iostream> #include<vector> #include<algorithm> #include<string> #include<stdlib.h> using namespace std; bool myComp(const vector<int>& a, const vector<int>& b){ if(a[1]>b[1]) return true; else if(a[1]<b[1]) return false; if(a[2]>b[2]) return true; else if(a[2]<b[2]) return false; if(a[3]>b[3]) return true; else if(a[3]<b[3]) return false; else return true; } int main(void){ int n; while(cin>>n){ vector<string> names; vector<vector<int>> datas; for(int i = 0; i < n; i++){ vector<int> t; for(int j = 0; j < 4; j++){ t.push_back(0); } datas.push_back(t); } for(int i = 0; i < n; i++){ datas[i][0] = i; } for(int i = 0; i < n; i++){ string t; cin>>t; names.push_back(t); } for(int i = 0; i < n*(n-1)/2; i++){ string t; cin>>t; int ind = t.find('-'); string name1 = t.substr(0,ind); string name2 = t.substr(ind+1,t.size()-ind-1); auto iter = find(names.begin(),names.end(),name1); int team1 = iter-names.begin(); iter = find(names.begin(),names.end(),name2); int team2 = iter-names.begin(); cin>>t; ind = t.find(':'); string s1 = t.substr(0,ind); string s2 = t.substr(ind+1,t.size()-ind-1); int score1 = atoi(s1.c_str()); int score2 = atoi(s2.c_str()); if(score1 > score2){ datas[team1][1] += 3; } else if(score1 == score2){ datas[team1][1] += 1; datas[team2][1] += 1; } else{ datas[team2][1] += 3; } datas[team1][2] += (score1-score2)>0?(score1-score2):0; datas[team2][2] += (score2-score1)>0?(score2-score1):0; datas[team1][3] += score1; datas[team2][3] += score2; } sort(datas.begin(), datas.end(), myComp); vector<int> res; for(int i = 0; i < n/2; i++){ int team = datas[i][0]; res.push_back(team); } sort(res.begin(), res.end()); for(int i = 0; i < n/2; i++){ cout<<names[res[i]]<<endl; } } return 0; }
过样例百分之0,这题有问题吧 #include <iostream> #include <vector> #include <string> #include <unordered_map> #include <cstdio> #include <unordered_set> #include <algorithm> using namespace std; struct team{ string name; int scores; int goals; int wingoals; team():name(),scores(0){} }teams[55]; bool cmp(team t1,team t2){ if(t1.scores!=t2.scores) return t1.scores>t2.scores; if(t1.wingoals!=t2.wingoals) return t1.wingoals>t2.wingoals; if(t1.goals!=t2.goals) return t1.goals>t2.goals; } bool cmp2(team t1,team t2){ return t1.name<t2.name; } int main() { // freopen("E:\input.txt","r",stdin); int n; int mactchnum; while(cin>>n){ vector<string> svec(n); unordered_map<string,int> mp; mactchnum=n*(n-1)/2; string tmp; for(int i=0;i<n;i++){ cin>>teams[i].name; mp[teams[i].name]=i; } for(int i=0;i<mactchnum;i++){ string a,b; cin>>tmp; int j=0; while(j!=tmp.size()&&tmp[j]!='-') ++j; a=tmp.substr(0,j-0); b=tmp.substr(j+1,tmp.size()-j-1); //cout<<a<<" "<<b<<" "; cin>>tmp; int s1=0,s2=0; j=0; while(tmp[j]!=':'){ s1=s1*10+tmp[j]-'0'; ++j; } ++j; while(j!=tmp.size()){ s2=s2*10+tmp[j]-'0'; ++j; } //printf("%d %d\n",s1,s2); teams[mp[a]].goals+=s1; teams[mp[a]].wingoals+=s1-s2; teams[mp[b]].goals+=s2; teams[mp[b]].wingoals+=s2-s1; if(s1==s2) { ++teams[mp[a]].scores; ++teams[mp[b]].scores; } else if(s1>s2) { teams[mp[a]].scores+=3; }else teams[mp[b]].scores+=3; } sort(teams,teams+n,cmp); sort(teams,teams+n/2,cmp2); for(int i=0;i<n;i++){ cout<<teams[i].name<<endl; //printf(" %d %d %d\n",teams[i].scores,teams[i].wingoals,teams[i].goals); } } }
JS做的,控制台调试也没问题...不知道是不是输入用法错了
var n = +read_line(); while (n > 0) { var result = {}; var printedResult = []; var l = n; while (l--) { var team = read_line(); result[team] = { point: 0, shoot: 0, lose: 0, sum: 0 }; } var number = n * (n - 1) / 2; while (numer--) { var str = read_line(); computeResult(str, result); } for (var i in result) { printedResult.push(result[i].sum); } printedResult.sort(function(a, b){ return b.slice(0, -1) - a.slice(0, -1) }) //排序 var printedArr = []; for (var i = 0; i < printedResult.length / 2; i++) { printedArr.push(printedResult[i].slice(-1)) } printedArr.sort(); for(var i = 0; i < printedArr.length;i++) { print(printedArr[i]) } n = +read_line(); } function computeResult(str, obj) { var a = str[0]; var b = str[2]; var c = +str[4]; //分数A var d = +str[6]; //分数B obj[a].shoot += c; obj[a].lose += d; obj[b].shoot += d; obj[b].lose += c; if (c > d) { obj[a].point += 3; } else if (c == d) { obj[a].point += 1; obj[b].point += 1; } else { obj[b].point += 3; } obj[a].sum = '' + obj[a].point + obj[a].shoot + obj[a].lose + a; // '555A' obj[b].sum = '' + obj[b].point + obj[b].shoot + obj[b].lose + b; // '424B' }
怀疑测试数据中存在N=1(奇数)的情况 过了0.4
#include <cstdio> #include <cstdlib> #include <iostream> #include <algorithm> #include <cmath> #include <map> using namespace std; const int MAXN = 55; struct Node { string nm; int sc1; int sc2; int sc3; }G[MAXN]; int N = 0; bool cmp1(const Node & P,const Node & T) { if (P.sc1 == T.sc1) { if (P.sc2 == T.sc2) return T.sc3 < P.sc3; else return T.sc2 < P.sc2; } else return T.sc1 < P.sc1; } bool cmp2(const Node & P,const Node & T) { return P.nm < T.nm; } inline void myINPUTstr(string & s1,string & s2) { string ss = ""; s1 = "" , s2 = ""; bool ok = true; cin >> ss; for (size_t i = 0; i < ss.length(); ++ i) { if (ss[i] == '-') ok = false; else { if (ok) s1.push_back(ss[i]); else s2.push_back(ss[i]); } } } //inline void myINPUTnum(int & x1,int &x2) void u0() { map<string,int> mp; mp.clear(); string str = ""; for (int i = 1; i <= N; ++ i) { cin >> str; mp[str] = i; G[i].nm = str; G[i].sc1 = G[i].sc2 = G[i].sc3 = 0; } string s1 = "", s2 = ""; char cc = 'a'; int x1 = 0, x2 = 0, ix = 0, iy = 0; for (int i = 1; i <= N; ++ i) { for (int j = i+1; j <= N; ++ j) { myINPUTstr(s1,s2); cin >> x1 >> cc >> x2; ix = mp[s1], iy = mp[s2]; G[ix].sc2 += (x1-x2); G[iy].sc2 += (x2-x1); G[ix].sc3 += x1; G[iy].sc3 += x2; if (x1 > x2) { G[ix].sc1 += 3; } else if (x1 == x2) { G[ix].sc1 += 1, G[iy].sc1 += 1; } else { G[iy].sc1 += 3; } } } ix = ((N+1)/2) + 1; sort(G+1,G+N+1,cmp1); for (int i = 1; i <= N; ++ i) { // cout << G[i].nm << " " << G[i].sc << endl; } sort(G+1,G+ix,cmp2); for (int i = 1; i < ix; ++ i) { cout << G[i].nm << endl; } } int main() { while (cin >> N) { u0(); } return 0; } /* 4 A B C D A-B 1:1 A-C 2:2 A-D 1:0 B-C 1:0 B-D 0:3 C-D 0:3 2 a A a-A 2:1 */
本地IDE直接把全部测试用例输进去,跑出来的结果一样,结果赛马AC0。
最开始是按顺序,D比A成绩好是D A,还改成A D了,依然AC0。
public class KDTwo { public static void main(String args[]) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()) { int n = scanner.nextInt(); Map<String,Team> map = new HashMap<>(); for (int i = 0; i < n; i++) { String tName = scanner.next(); map.put(tName,new Team(tName)); } int allCom = n * (n-1) / 2; for (int i = 0; i < allCom; i++) { String strTeam = scanner.next(); String strScore = scanner.next(); solveStr(strTeam,strScore , map); } ArrayList<Team> rsList = getAnswer(map); ArrayList<Team> indexList = getAnswer(map); for (int i = 0; i < rsList.size(); i++) { indexList.add(rsList.get(i)); } Collections.sort(indexList); int num = indexList.get(indexList.size()/2).result; for (int i = 0; i < rsList.size(); i++) { if(rsList.get(i).result > num) { System.out.println(rsList.get(i).name); } } } } public static ArrayList getAnswer(Map<String,Team> map) { ArrayList<Team> list = new ArrayList<>(); Iterator iter = map.entrySet().iterator(); while (iter.hasNext()) { Map.Entry entry = (Map.Entry) iter.next(); list.add((Team)entry.getValue()); } return list; } public static void solveStr(String str1,String str2,Map<String,Team> map) { String[] teamIn = str1.split("-"); String[] goalIn = str2.split(":"); Team team1 = map.get(teamIn[0]); Team team2 = map.get(teamIn[1]); if(Integer.parseInt(goalIn[0]) > Integer.parseInt(goalIn[1])) { team1.result = team1.result + 3; team2.result = team2.result + 0; } else if(Integer.parseInt(goalIn[0]) == Integer.parseInt(goalIn[1])) { team1.result = team1.result + 1; team2.result = team2.result + 1; } else { team1.result = team1.result + 0; team2.result = team2.result + 3; } team1.goal += Integer.parseInt(goalIn[0]); team1.goalEd += Integer.parseInt(goalIn[1]); team2.goal += Integer.parseInt(goalIn[1]); team2.goalEd += Integer.parseInt(goalIn[0]); } } class Team implements Comparable<Team>{ public String name; public int result; //分数 public int goal; //进球数 public int goalEd; //被进球数 public Team() { } public Team(String name) { this.name = name; } public int getGoalDiff() { return (goal - goalEd); } public int getGoal(){ return goal; } [@Override](/user/Override) public int compareTo(Team team) { if(this.result > team.result) { return -1; } else if(this.result < team.result) { return 1; } else { if( (this.getGoalDiff()) > (team.getGoalDiff())) { return -1; } else if( (this.getGoalDiff()) < (team.getGoalDiff())) { return 1; } else { if(this.getGoal() > team.getGoal()) { return -1; } else { return 1; } } } } }
#include<iostream> #include<string> #include<map> #include<vector> #include<algorithm> using namespace std; struct Score { string s; int score, count1, count2; Score() { score = 0; count1 = 0; count2 = 0; } }; bool cmp(Score A, Score B) { if (A.score == B.score) { if (A.count1 == B.count1) return A.count2 > B.count2; else return A.count1 > B.count1; } else return A.score > B.score; } int main() { int n; while (cin >> n) { map<string, int> m; string str; for (int i = 0; i < n; i++) { cin >> str; m[str] = i; } string s1, s2; int num1, num2; char ch; vector<Score> vec(n); for (int i = 0; i < n*(n - 1) / 2; i++) { cin >> s1 >> num1 >> ch >> num2; s2 = s1.substr(s1.find('-') + 1); s1 = s1.substr(0, s1.find('-')); if (num1 > num2) { vec[m[s1]].s = s1; vec[m[s2]].s = s2; vec[m[s1]].score += 3; vec[m[s1]].count1 += (num1 - num2); vec[m[s1]].count2 += num1; vec[m[s2]].count2 += num2; } else if (num1 < num2) { vec[m[s1]].s = s1; vec[m[s2]].s = s2; vec[m[s2]].score += 3; vec[m[s2]].count1 += (num2 - num1); vec[m[s2]].count2 += num2; vec[m[s1]].count2 += num1; } else { vec[m[s1]].s = s1; vec[m[s2]].s = s2; vec[m[s1]].score += 1; vec[m[s2]].score += 1; vec[m[s2]].count2 += num2; vec[m[s1]].count2 += num1; } } sort(vec.begin(), vec.end(), cmp); vector<string> res; for (int i = 0; i < n / 2; i++) { res.push_back(vec[i].s); } sort(res.begin(), res.end()); for (int i = 0; i < res.size(); i++) { cout << res[i] << endl; } } return 0; }
我通过了
#include<map> #include<string> #include<iostream> #include<cstdio> #include<vector> #include<set> #include<cstring> using namespace std; int main() { int n; while (scanf("%d", &n)!=EOF) { map<string, vector<int>>sc;//score,num map<vector<int>, string>sc2n; set<string> ans; char name[50] = { '\0' }; for (int i = 0; i < n; i++) { scanf("%s",name); sc[name] = { 0,0,0 }; } int line_num = n*(n - 1) / 2; char name1[100] = { '\0' }; char name2[100] = { '\0' }; int num1 = 0; int num2 = 0; for (int i = 0; i < line_num; i++) { scanf("%s %d:%d", name1, &num1, &num2); int sep = (int)(strchr(name1, '-') - name1); strcpy(name2, name1 + sep + 1); name1[sep] = '\0'; if (num1 == num2) { sc[name1][0]++; sc[name2][0]++; } else if (num1 > num2) { sc[name1][0] += 3; sc[name1][1] += num1-num2; } else { sc[name2][0] += 3; sc[name2][1] += -(num1 - num2); } sc[name1][2] += num1; sc[name2][2] += num2; } for (auto &e : sc) sc2n[e.second] = e.first; int cnt = 0; auto rit = sc2n.rbegin(); for (; rit != sc2n.rend();rit++) { auto &e = *rit; ans.insert(e.second); cnt++; if (cnt == n / 2) break; } for(auto &e:ans) printf("%s\n", e.c_str()); } return 0; }
%0,不知道为啥
没做完,分享下自己的思路吧
import java.util.Scanner; public class Main { public static void main(String args[]){ Scanner sc = new Scanner(System.in); int n = sc.nextInt();//球队数 doi(n,sc); while(sc.hasNext()) doi(n,sc); sc.close(); } public static void doi(int n,Scanner sc){ team[] sdui = new team[n]; for(int i=0;i<n;i++){ sdui[i].name = sc.next(); } for(int i=0;i<n*(n-1)/2;i++){ String s = sc.nextLine(); String[] st = s.split(" "); String tA = st[0].split("-")[0]; String tB = st[0].split("-")[1]; int numA = Integer.parseInt(st[1].split(":")[0]); int numB = Integer.parseInt(st[1].split(":")[1]); int ta= findteam(sdui,tA); int tb = findteam(sdui,tB); if(numA>numB){ sdui[ta].countA+=3; }else if(numA==numB){ }else{ } } } public static int findteam(team[] sdui,String name){ for(int i=0;i<sdui.length;i++){ if(sdui[i].name.equals(name)) return i; } return -1; } class team{ String name; int countA; int countB; int countC; } }
import java.util.*;
/**
* Created by 78284 on 2017/8/29.
*/
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while(in.hasNext()){
Map<String , Integer> map1 = new LinkedHashMap<>();//进球数
Map<String , Integer> map2 = new LinkedHashMap<>();//净胜球数
Map<String , Integer> map3 = new LinkedHashMap<>();//积分
int n = Integer.parseInt(in.nextLine());
for(int i = 0 ;i<n;i++){
String t = in.nextLine();
map1.put(t,0);
map2.put(t,0);
map3.put(t,0);
}
for(int i =0 ;i<n*(n-1)/2;i++){
String str = in.nextLine();
String [] newstr = str.split(" ");
String [] front = newstr[0].split("-");
String [] behind = newstr[1].split(":");
//存入进球数
map1.put(front[0],map1.get(front[0])+Integer.parseInt(behind[0]));
map1.put(front[1],map1.get(front[1])+Integer.parseInt(behind[1]));
map2.put(front[0],map2.get(front[0])+Integer.parseInt(behind[0])-Integer.parseInt(behind[1]));
map2.put(front[1],map2.get(front[1])+Integer.parseInt(behind[0])-Integer.parseInt(behind[1]));
if(behind[0].compareTo(behind[1])>0){
map3.put(front[0],map3.get(front[0])+3);
}else if(behind[0].compareTo(behind[1])==0){
map3.put(front[0],map3.get(front[0])+1);
map3.put(front[1],map3.get(front[1])+1);
}else{
map3.put(front[1],map3.get(front[1])+3);
}
}
String [] str = new String[100];
int [] val = new int[100];
int i=0,y=0;
for(String key:map3.keySet()){
str[i++] = key;
val[y++] = map3.get(key);
}
for(int j = 0 ;j<n-1;j++){
for(int k=0;k<n-j-1;k++){
if(val[k]<val[k+1]){
int temp = val[k];
val[k]=val[k+1];
val[k+1]=temp;
String s = str[k];
str[k]=str[k+1];
str[k+1] = s;
}else if(val[k]==val[k+1]){
if(map2.get(str[k])<map2.get(str[k+1])){
int temp = val[k];
val[k]=val[k+1];
val[k+1]=temp;
String s = str[k];
str[k]=str[k+1];
str[k+1] = s;
}else if(map2.get(str[k])==map2.get(str[k+1])){
if(map1.get(str[k])<map1.get(str[k+1])){
int temp = val[k];
val[k]=val[k+1];
val[k+1]=temp;
String s = str[k];
str[k]=str[k+1];
str[k+1] = s;
}
}
}
}
}
for(i= 0 ;i<n/2-1;i++){
for(int j= 0 ;j<n/2-1-i;j++){
if(str[j].compareTo(str[j+1])>0){
String s = str[j];
str[j]=str[j+1];
str[j+1]= s;
}
}
}
for(i=0;i<n/2;i++){
System.out.println(str[i]);
}
}
}
}
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
public class Mian5 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (true) {
int n = Integer.parseInt(scanner.nextLine());
int n1=n*(n-1)/2;
Map<String,Score> map =new TreeMap<String,Score>();
for (int i = 0; i < n; i++) {
String name=scanner.nextLine();
map.put(name, new Score(name));
}
for (int i = 0; i < n1; i++) {
String temp=scanner.nextLine();
String a=temp.substring(0,1);
String b=temp.substring(2,3);
int a1=Integer.parseInt(temp.substring(4,5));
int b1=Integer.parseInt(temp.substring(6,7));
if(a1>b1){
Score score1=map.get(a);
Score score2=map.get(b);
score1.score+=3;
score1.goal+=a1-b1;
score2.goal-=a1-b1;
score1.winTeam.add(b);
}else if(a1<b1){
Score score1=map.get(b);
Score score2=map.get(a);
score1.score+=3;
score1.goal+=b1-a1;
score2.goal-=b1-a1;
score1.winTeam.add(a);
}else{
Score score1=map.get(a);
Score score2=map.get(b);
score1.score+=1;
score2.score+=1;
}
}
Set<Score> set = new TreeSet<Score>();
for(String s:map.keySet()){
set.add(map.get(s));
}
Iterator<Score> iterator = set.iterator();
for (int i = 0; i < n/2; i++) {
iterator.next();
}
for (int i = 0; i < n/2; i++) {
System.out.println(iterator.next().teamName);
}
}
}
}
//4
//A
//B
//C
//D
//A-B 1:1
//A-C 2:2
//A-D 1:0
//B-C 1:0
//B-D 0:3
//C-D 0:3
class Score implements Comparable {
int score = 0;
int goal = 0;
String teamName;
Set<String> winTeam = new TreeSet<String>();
public Score(String name){
teamName=name;
}
[@Override](/user/Override)
public int compareTo(Object o) {
Score s = (Score) o;
if (this.score - s.score != 0) {
return 100*(this.score - s.score);
} else {
if(this.goal-s.goal!=0){
return 10*(this.goal-s.goal);
}else{
if(this.winTeam.contains(s.teamName)){
return 1;
}else{
return-1;
}
}
}
}
}
考试结束了,问题找出来了,好气啊!!!
import java.util.HashMap; import java.util.Scanner; public class Main { public static void win(String[] str, String[] _str){ if(str == null || _str == null) return; HashMap<String, Integer> map = new HashMap<String,Integer>(); HashMap<String, Integer> map1 = new HashMap<String,Integer>(); for(int i = 0; i < str.length; i++){ map.put(str[i], 0); map1.put(str[i], 0); } String[] t1 = new String[_str.length/2]; String[] t2 = new String[_str.length/2]; int p = 0, q = 0; for(int i = 0; i < _str.length; i++){ if(i % 2 == 0){ t1[p++] = _str[i]; }else{ t2[q++] = _str[i]; } } for(int i = 0; i < t1.length; i++){ String[] temp1 = t1[i].split("-"); String[] temp2 = t2[i].split(":"); map1.put(temp1[0], map1.get(temp1[0]) + Integer.parseInt(temp2[0])); map1.put(temp1[1], map1.get(temp1[1]) + Integer.parseInt(temp2[1])); int num = Integer.parseInt(temp2[0]) - Integer.parseInt(temp2[1]); if(num > 0){ map.put(temp1[0], map.get(temp1[0]) + 3); }else if(num < 0){ map.put(temp1[1], map.get(temp1[1]) + 3); }else{ map.put(temp1[0], map.get(temp1[0]) + 1); map.put(temp1[1], map.get(temp1[1]) + 1); } } int count = 0; String lastname = ""; for(String name : map.keySet()){ int temp = map.get(name); if(temp > count){ count = temp; lastname = name; }else if(temp == count){ if(map1.get(lastname) < map1.get(name)) lastname = name; } } System.out.println(lastname); } public static void main(String[] args) { // TODO Auto-generated method stub Scanner in = new Scanner(System.in); int n = in.nextInt(); String[] str = new String[n]; for(int i = 0; i < n; i++){ str[i] = in.next(); } String[] _str = new String[n * (n - 1)]; for(int j = 0; j < _str.length; j++){ _str[j] = in.next(); } win(str,_str); } }
import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Scanner; public class Main2 { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNextInt()) { int n = in.nextInt(); in.nextLine(); HashMap<String, Integer> map = new HashMap<String, Integer>(); for (int i = 0; i < n; i++) { String tmp = in.nextLine(); map.put(tmp, 0); } for (int k = 0; k < n * (n - 1) / 2; k++) { String[] tmp = in.nextLine().split(" "); String[] groups = tmp[0].split("-"); String[] counts = tmp[1].split(":"); if (Integer.valueOf(counts[0]) == Integer.valueOf(counts[1])) { map.put(groups[0], map.get(groups[0]) + 1); map.put(groups[1], map.get(groups[1]) + 1); } else if (Integer.valueOf(counts[0]) > Integer .valueOf(counts[1])) { map.put(groups[0], map.get(groups[0]) + 3); } else { map.put(groups[1], map.get(groups[1]) + 3); } } List<Map.Entry<String, Integer>> entryList = new ArrayList<Map.Entry<String, Integer>>( map.entrySet()); Collections.sort(entryList, new Comparator<Map.Entry<String, Integer>>() { [@Override](/user/Override) public int compare(Entry<String, Integer> o1, Entry<String, Integer> o2) { // TODO Auto-generated method stub return (o2.getValue() - o1.getValue()); } }); ArrayList<String> list = new ArrayList<String>(); for (int i = 0; i < n / 2; i++) { list.add(entryList.get(i).getKey()); } Collections.sort(list); for (int i = 0; i < list.size(); i++) { System.out.println(list.get(i)); } } } }
0%
import java.util.*;
public class KE1 {
public static void main(String[] args){
Scanner in =new Scanner(System.in);
while(in.hasNext()){
int n=in.nextInt();
String[] str =new String[n];
for(int i=0;i<n;i++){
str[i]=in.next();
}
String[] score =new String[n*(n-1)/2];
in.nextLine();
//System.out.println(n*(n-1)/2);
for(int j=0;j<(n*(n-1)/2);j++){
score[j]=in.nextLine();
}
game(str,score);
}
}
public static void game(String[] name,String[] core){
int n =name.length;
int[] rec =new int[n];
//int[] small = new int[7];
for(int i=0;i<core.length;i++){
String ss =core[i];
int c5 =Integer.parseInt(String.valueOf(ss.charAt(4)));
int c7=Integer.parseInt(String.valueOf(ss.charAt(6)));
if(c5>c7){
rec[find(name, ss.charAt(0))]+=3;
}else if(c5==c7){
//System.out.println(ss.charAt(0));
rec[find(name, ss.charAt(0))]+=1;
rec[find(name, ss.charAt(2))]+=1;
}else{
rec[find(name, ss.charAt(2))]+=3;
}
}
List<Integer> list = new ArrayList<>();
for(int j=0;j<n;j++){
list.add(rec[j]);
}
Collections.sort(list);
TreeSet<String> set =new TreeSet<>();
int len =list.size();
for(int p=0;p<(n/2);p++){
for(int k=0;k<n;k++){
if(rec[k]==list.get(len-1)){
set.add(name[k]);
len--;
break;
}
}
}
for(String c:set){
System.out.println(c);
}
}
public static int find(String[] n,char s1){
for(int i=0;i<n.length;i++){
char ch =n[i].charAt(0);
if(s1==ch) return i;
}
return 0;
}
}
package xiaozhao; import java.util.*; public class t3 { public static void main(String args[]) { Scanner scanner = new Scanner(System.in); int n = Integer.parseInt(scanner.nextLine()); Map<String, team> map = new HashMap<String, team>(); for (int i = 0; i < n; i++) { String name = scanner.nextLine(); team t = new team(name); map.put(name, t); } for (int i = 0; i < (n * (n - 1) / 2); i++) { String str = scanner.nextLine(); String s[] = str.split(" "); String name1 = s[0].split("-")[0]; String name2 = s[0].split("-")[1]; team t1 = map.get(name1); team t2 = map.get(name2); String scores[] = s[1].split(":"); int s1 = Integer.parseInt(scores[0]); int s2 = Integer.parseInt(scores[1]); t1.setGoal(t1.getGoal() + s1); t2.setGoal(t2.getGoal() + s2); t1.setWin(t1.getWin() + s1 - s2); t2.setWin(t2.getWin() + s2 - s1); if (s1 > s2) { t1.setScore(t1.getScore() + 3); } else if (s1 == s2) { t1.setScore(t1.getScore() + 1); t2.setScore(t2.getScore() + 1); } else { t2.setScore(t1.getScore() + 3); } } team arr[] = new team[n]; int k = 0; for (String str : map.keySet()) { arr[k++] = map.get(str); } Arrays.sort(arr); for (int i = arr.length-1; i>=arr.length/2; i--) { System.out.println(arr[i].getName()); } } } package xiaozhao; import java.util.Comparator; public class team implements Comparable { private String name; private int score; private int goal; private int win; public team(String name, int score, int goal) { this.name = name; this.score = score; this.goal = goal; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getScore() { return score; } public void setScore(int score) { this.score = score; } public int getGoal() { return goal; } public int getWin() { return win; } public void setWin(int win) { this.win = win; } public void setGoal(int goal) { this.goal = goal; } public team(String name) { this.name = name; this.goal=0; this.score=0; this.win=0; } public int compareTo(Object o) { team t = (team) o; if (this.score > t.score) { return 1; } else if (this.score == t.score) { if (this.win == t.win) { return this.goal > t.goal ? 1 : -1; } return this.win > t.win ? 1 : -1; } else { return -1; } } }
import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Scanner; public class MyFootball { public static void main(String[] args) { Scanner in = new Scanner(System.in); while(in.hasNext()){ Map<String,Integer> score = new HashMap<String,Integer>();//存放分数 Map<String,Integer> winNumber = new HashMap<String,Integer>();//存放净胜球数 Map<String,Integer> number = new HashMap<String,Integer>();//存放进球数 int count = Integer.parseInt(in.nextLine()); for(int i = 0;i<count;i++){ String t = in.nextLine(); score.put(t, 0); winNumber.put(t, 0); number.put(t, 0); } for(int i =0;i<count*(count-1)/2;i++){ String[] str = in.nextLine().split(" "); String[] pre = str[0].split("-"); String[] scores = str[1].split(":"); int score1 = Integer.parseInt(scores[0]); int score2 = Integer.parseInt(scores[1]); winNumber.put(pre[0], winNumber.get(pre[0])+score1-score2); winNumber.put(pre[1], winNumber.get(pre[1])+score2-score1); number.put(pre[0], number.get(pre[0])+score1); number.put(pre[1], number.get(pre[1])+score2); if(score1>score2){ score.put(pre[0], score.get(pre[0])+3); } else if(score1<score2){ score.put(pre[1], score.get(pre[1])+3); } else{ score.put(pre[1], score.get(pre[1])+1); score.put(pre[0], score.get(pre[0])+1); } } //给list排序 List<Entry<String, Integer>> list = new ArrayList<Entry<String, Integer>>(score.entrySet()); for(int i =0;i<list.size();i++){ for(int j =i+1;j<list.size();j++){ if(list.get(i).getValue()>list.get(j).getValue()){ Entry temp = list.get(i); list.set(i, list.get(j)); list.set(j,temp); } else if(list.get(i).getValue()==list.get(j).getValue()){ if(winNumber.get(list.get(i).getKey())>winNumber.get(list.get(j).getKey())){ Entry temp = list.get(i); list.set(i, list.get(j)); list.set(j,temp); } } } } for(int i = count/2;i<count;i++){ System.out.println(list.get(i).getKey()); } } } }
#include <iostream> #include <vector> #include <map> #include <set> using namespace std; class groupInfo { public: groupInfo() {}; groupInfo(char c):groupName_m(c), score_m(0), gd_m(0), gi_m(0) {} groupInfo(char c, vector<int> info):groupName_m(c), score_m(info[0]), gd_m(info[1]),gi_m(info[2]) {} const char getGroupName() const { return groupName_m; } const int getScore() const { return score_m; } void addScore(int score) { score_m += score; } const int getGd() const { return gd_m; } void addGd(int gd) { gd_m += gd; } const int getGi() const { return gi_m; } void addGi(int gi) { gi_m += gi; } void addInfo(vector<int> info) { addScore(info[0]); addGd(info[1]); addGi(info[2]); } bool operator>(const groupInfo & gI) const { if(score_m > gI.getScore()) { return true; } else if (score_m == gI.getScore()) { if(gd_m > gI.getGd()) return true; else if(gd_m == gI.getGd()) { if(gi_m > gI.getGi()) return true; } } return false; } private: char groupName_m; int score_m; int gd_m; int gi_m; }; vector<vector<int>> figureInfo(const string& str) { vector<vector<int>> VV; vector<int> V0; vector<int> V2; if(str[0] == str[2]) { V0.push_back(1); V2.push_back(1); } else if(str[0] > str[2]) { V0.push_back(3); V2.push_back(0); } else { V0.push_back(0); V2.push_back(3); } V0.push_back(str[0] - str[2]); V2.push_back(str[2] - str[0]); V0.push_back(str[0]); V2.push_back(str[2]); VV.push_back(V0); VV.push_back(V2); return VV; } int main(int argc, const char * argv[]) { int n; while (cin >> n) { int vectoryNums = n/2; int battalNums = n*(n-1)/2; map<char, groupInfo> gnameInfo; while (n--) { char gName; cin >> gName; groupInfo group(gName); gnameInfo[gName] = group; } while (battalNums--) { string strName, strScore; cin >> strName >> strScore; vector<vector<int>> VV = figureInfo(strScore); gnameInfo[strName[0]].addInfo(VV[0]); gnameInfo[strName[2]].addInfo(VV[1]); } set<groupInfo, greater<groupInfo>> groupInfoSet; for(auto v : gnameInfo) { groupInfoSet.insert(v.second); } int i = 0; set<char> groupNameSet; for(auto v : groupInfoSet) { i++; if(i > vectoryNums) break; groupNameSet.insert(v.getGroupName()); } for(auto v : groupNameSet) { cout << v << endl; } } return 0; }