Ultraviolet A Problem 10194 football (aka soccer) (soccer)

Source: Internet
Author: User
Tags dot net
// Football (aka soccer) // PC/Ultraviolet IDs: 110408/10194, popularity: B, success rate: average level: 1 // verdict: accepted // submission date: 2011-05-27 // UV Run Time: 0.020 S // copyright (c) 2011, Qiu. Metaphysis # Yeah dot net // it is complicated to read data. Others are the sorting and comparison functions. It is relatively easy, but error-prone. # Include <iostream> # include <algorithm> using namespace STD; # define team_size 30 // define a structure to save information about the team. Struct team {string name; // team name. Int points; // score. Int wins; // The number of wins. Int ties; // Number of draws. Int losses; // number of input sessions. Int goals_scored; // Number of balls. Int goals_lossed; // Number of dropped balls. Int games; // number of participants. Actually equal to wins + ties + losses .}; // Sort by various conditions. Bool CMP (Team X, Team y) {If (X. Points! = Y. Points) return X. Points> Y. Points; If (X. wins! = Y. Wins) return X. Wins> Y. wins; If (X. goals_scored-X. goals_lossed )! = (Y. goals_scored-y. goals_lossed) Return (X. goals_scored-X. goals_lossed)> (Y. goals_scored-y. goals_lossed); If (X. goals_scored! = Y. goals_scored) return X. goals_scored> Y. goals_scored; If (X. Games! = Y. games) return X. games <Y. games; For (INT I = 0; I <min (X. name. length (), Y. name. length (); I ++) {If (isalpha (X. name. at (I) & isalpha (Y. name. at (I) {If (X. name. at (I )! = Y. name. at (I) return tolower (X. name. at (I) <tolower (Y. name. at (I);} elsereturn X. name. at (I) <Y. name. at (I);} return X. name. length () <Y. name. length ();} int find_index (string name, Team teams [], int capacity) {for (INT I = 0; I <capacity; I ++) if (teams [I]. name = Name) return I; Return-1;} void Init (Team teams []) {for (INT I = 0; I <team_size; I ++) {teams [I]. name = ""; teams [I]. points = 0; teams [I]. wins = 0; teams [I]. ties = 0; teams [I]. losses = 0; teams [I]. goals_scored = 0; teams [I]. goals_lossed = 0; teams [I]. games = 0 ;}} int main (int ac, char * AV []) {INT cases, capacity; team teams [team_size]; string line; CIN> cases; cin. ignore (); While (cases --) {// initialize the structure array. Init (teams); // read the competition name and echo it. Getline (CIN, line); cout <line <Endl; // read the team name. Int number; CIN> Number; cin. ignore (); capacity = 0; while (number --) Getline (CIN, teams [capacity ++]. name); // read and parse the competition data. Cin> Number; cin. ignore (); While (number --) {Getline (CIN, line); int begin = line. find_first_of ('#'); int end = line. find_last_of ('#'); string namex = line. substr (0, begin); string namey = line. substr (end + 1); string result = line. substr (begin + 1, end-begin-1); int middle = result. find_first_of ('@', 0); int goalsx = atoi (result. substr (0, middle ). data (); int goalsy = atoi (result. substr (middle + 1 ). dat A (); int indexx = find_index (namex, teams, capacity); int indexy = find_index (namey, teams, capacity); teams [indexx]. goals_scored + = goalsx; teams [indexy]. goals_scored + = goalsy; teams [indexx]. goals_lossed + = goalsy; teams [indexy]. goals_lossed + = goalsx; teams [indexx]. wins + = (goalsx> goalsy )? 1: 0); teams [indexy]. Wins + = (goalsy> goalsx )? 1: 0); teams [indexx]. Ties + = (goalsx = goalsy )? 1: 0); teams [indexy]. Ties + = (goalsx = goalsy )? 1: 0); teams [indexx]. Losses + = (goalsx <goalsy )? 1: 0); teams [indexy]. Losses + = (goalsy <goalsx )? 1: 0); teams [indexx]. games + = 1; teams [indexy]. games + = 1; if (goalsx = goalsy) {teams [indexx]. points + = 1; teams [indexy]. points + = 1;} else {teams [indexx]. points + = (goalsx> goalsy )? 3: 0); teams [indexy]. Points + = (goalsy> goalsx )? 3: 0) ;}/// sort. Sort (teams, teams + capacity, CMP); // output. For (INT I = 0; I <capacity; I ++) {cout <(I + 1) <")" <teams [I]. name <"; cout <teams [I]. points <"P,"; cout <teams [I]. games <"G ("; cout <teams [I]. wins <"-"; cout <teams [I]. ties <"-"; cout <teams [I]. losses <"),"; cout <(teams [I]. goals_scored-teams [I]. goals_lossed) <"GD ("; cout <teams [I]. goals_scored <"-"; cout <teams [I]. goals_lossed <")" <Endl ;}if (cases) cout <Endl ;}return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.