Competition statistics of Huawei OJ Training Questions, Huawei oj
The questions are as follows:
Competition statistics
There is a game platform where each participating team (identified by a unique TeamID) performs a single round-robin competition. Only one competition is held between the two teams to determine the number of winning or losing points. You need to complete a program for statistics of the competition conditions, and be able to query the latest competition conditions of the specified team at any time: including the number of winning, flat, and negative bureaus, current total points, and rankings.
Note: When the round robin ends, you can query the latest competition conditions of a certain team.
Rule Description
Match determination: one of the two teams has the highest score as the winner and the other has the same score as the draw.
Points rules: each game: three points for the winner, one point for each draw, and zero for the negative.
Ranking rules: the ranking starts from 1 according to the current total points. When n (n> = 2) teams rank in parallel, n-1-1 ranks below the same rank are empty.
If the following specifications or constraints are met, the examinee program does not need to be checked:
(1) Total number of competition teams <= 1000 <>
(2) 0 <= teamid <= 65535 <>
(3) total points for each team <= 65535 <>
(4) One-to-two match. One-to-one match indicates the same match.
(5) do not repeat the results of the same game
(6) do not compete with yourself
The results of the first two rounds of the round robin are as follows:
|
Team 1ID |
Team 1 score |
Team 2ID |
Team 2 score |
Competition 1 |
1 |
34 |
2 |
45 |
Competition 2 |
2 |
40 |
3 |
40 |
Input:
Match information of each other, in the format of team id and score, for example, 1 2 34 45, that is, the score of the two teams with ID 1 and 2 is 34 and 45. data in the results of a match are separated by spaces;
Output:
The scores sorted by rankings are
Team ID |
Number of wins |
Number of draws |
Negative field count |
Total points |
Ranking |
2 |
1 |
1 |
0 |
4 |
1 |
That's 211041
Test example:
Input: 1 2 34 45 2 3 4040 1 3 35 45
Output: 1 0 0 2 0 3 2 1 10 4 1 3 1 1 0 4 1
My program --
Package Tran0624; import java. util. arrayList; import java. util. collections; import java. util. hashMap; import java. util. iterator; import java. util. imports; import java. util. set; import java. util. treeSet; public class Main {private static HashMap <Integer, Troop> list; public static void main (String [] args) {role metadata = new partition (System. in); String string = bytes. nextLine (); String [] ssStrings = string. split (""); // four is a match // each group of data, Team id, score int n = ssStrings. length; int [] dataArray = new int [n]; list = new HashMap <Integer, Troop> (); boolean existFlag = false; for (int I = 0; I <n; I ++) {dataArray [I] = Integer. parseInt (ssStrings [I]) ;}for (int I = 0; I <n; I ++) {if (I % 4 = 0) | (I % 4 = 1) {list. put (dataArray [I], new Troop (dataArray [I]);} else if (I % 4 = 2) {if (dataArray [I]> dataArray [I + 1]) {list. get (dataArray [I-2]). setWinNum (list. get (dataArray [I-2]). getWinNum () + 1); list. get (dataArray [I-2]). setScores (list. get (dataArray [I-2]). scores + 3); list. get (dataArray [I-1]). setFailNum (list. get (dataArray [I-1]). getFailNum () + 1);} else if (dataArray [I] = dataArray [I + 1]) {list. get (dataArray [I-2]). setdomainnum (list. get (dataArray [I-2]). get1_num () + 1); list. get (dataArray [I-2]). setScores (list. get (dataArray [I-2]). scores + 1); list. get (dataArray [I-1]). setdomainnum (list. get (dataArray [I-1]). get1_num () + 1); list. get (dataArray [I-1]). setScores (list. get (dataArray [I-1]). scores + 1);} else if (dataArray [I] <dataArray [I + 1]) {list. get (dataArray [I-1]). setWinNum (list. get (dataArray [I-1]). getWinNum () + 1); list. get (dataArray [I-1]). setScores (list. get (dataArray [I-1]). scores + 3); list. get (dataArray [I-2]). setFailNum (list. get (dataArray [I-2]). getFailNum () + 1) ;}}} Set <Integer> set = list. keySet (); Iterator <Integer> iterator = set. iterator (); ArrayList <Troop> mapArrayList = new ArrayList <Main. troop> (); while (iterator. hasNext () {mapArrayList. add (list. get (iterator. next ();} Collections. sort (mapArrayList); for (int j = 0; j <mapArrayList. size (); j ++) {System. out. println (mapArrayList. get (j ). toString () ;}} public static class Troop implements Comparable <Troop> {private int id = 0; private int winNum = 0; // Number of victories private int partition num = 0; // draw private int failNum = 0; // number of negative games private int scores = 0; // points public Troop (int id) {this. id = id ;}@ Overridepublic int compareTo (Troop o) {return o. id;} public int getId () {return id;} public void setId (int id) {this. id = id;} public int getWinNum () {return winNum;} public void setWinNum (int winNum) {this. winNum = winNum;} public int get1_num () {return 1_num;} public void set1_num (int 1_num) {this. interval num = interval num;} public int getFailNum () {return failNum;} public void setFailNum (int failNum) {this. failNum = failNum;} public int getScores () {return scores;} public void setScores (int scores) {this. scores = scores ;}@ Overridepublic String toString () {return "" + id + winNum + interval num + failNum + scores; // "Troop [id =" + id + ", winNum = "+ winNum +", interval num = "// + interval num +", failNum = "+ failNum +", scores = "+ scores // + ", rank = "+ rank +"] ";}}
Word statistics for a C ++ oj question
Core code:
Int flag = 0, count = 0;
For (int I = 0; I <n; I ++)
{
If (isalpha (a [I]) & flag = 0)
{
Flag = 1;
Count ++;
If (a [I] = ',' | a [I] = ''| a [I] = '.')
Flag = 0;
}
C ++ has two getline functions, which are defined in different header files respectively.
1. getline () is a row defined in <string>. It is used to enter a string and ends with enter.
Function prototype: getline (cin, str );
Cin: input stream object of istream class
Str: string object to be input
Example 1:
[Cpp] view plaincopy
// Chapter 4 Programming Exercise 1 of C ++ primary plus
# Include <iostream>
# Include <string>
Using namespace std;
String fname;
String lname;
Char grade;
Int age;
Int main ()
{
Cout <"What is your first name? ";
Getline (cin, fname );
Cout <"What is your last name? ";
Getline (cin, lname );
Cout <"What letter grade do you deserve? ";
Cin> grade;
Cout <"What is your age? ";
Cin> age;
Cout <"Name:" <lname <"," <fname <endl <"Grade:" <grade <endl <"Age: "<age <endl;
System ("pause ");
Return (0 );
}
2. cin. getline (char ch [], size) is a member function of cin. It is defined in <iostream> and is used to input a string with the specified size in the row and ends with enter. If the input length exceeds the size, subsequent input is no longer accepted.
Example 2:
[Cpp] view plaincopy
// Chapter 4 Programming Exercise 1 of C ++ primary plus
# Include <iostream>
Using namespace std;
Char fname [5];
Char lname [5];
Char grade;
Int age;
Int main ()
{
Cout <"What is your ...... remaining full text>
The following questions can be trained by the application to answer questions that are based on statistics.
1. Solution
Planned completion (%) number of companies number of scheduled tasks number of groups actual completion number of values (%)
90 ~ 100 3 80 95 76
100 ~ 110 12 400 105 420
110 ~ 120 5 120 115 138
Total 20 600-634
Average completion degree = actual completion count/planned task count * 100% = 634/600 * 100% = 105.67%
Thank you!
Vegetable name Price (RMB/kg) x transaction amount (RMB) m transaction volume (kg) m/x
Tudou 1.2 1200 1000
Rape 1.6 3200 2000
Mushroom 2.2 2200 1000
Total: 6600 4000
Average prices of vegetables = Σ m/x = 6600/4000 = 1.65 (RMB)