Ultraviolet A 10194-Football (aka Soccer)

Source: Internet
Author: User

After reading the meaning of this question, it is very easy. In addition to the usage of the gets () function, pay attention to it. The gets () function can receive space characters and absorb the line breaks after the carriage return ends. However, the scanf () function uses spaces and line breaks as the input Terminator and does not absorb the Terminator. Therefore, if the scanf () function exists before gets (), you must add the getchar () function to absorb the sanf () function Terminator. This question was submitted 15 times before it was passed. Note: 1. The last dictionary order of the rule is case-insensitive. 2. The number of players in the two teams is less than 20. If you use a string to directly receive the results of each game, pay special attention to the processing. 3. There cannot be line breaks at the end of the output file. [Cpp] # include <stdio. h> # include <stdlib. h> # include <string. h> struct Team {char name [50]; int B, c, d, e, f, g, h, I;} team [50]; int n, t, g; int find (char str []) {for (int I = 0; I <t; I ++) if (0 = strcmp (team [I]. name, str) return I; return 0;} // converts a string in upper case to lower case void UTL (char str []) {int len = strlen (str ); for (int I = 0; I <len; I ++) if (str [I]> = 'A' & str [I] <= 'Z ') {str [I] + = ('A'-'A') ;}} int Cmp (const void * _ a, const void * _ B) {struct Team * a = (struct Team *) _ a; struct Team * B = (struct Team *) _ B; if (a-> B! = B-> B) return B-> B-a-> B; if (a-> d! = B-> d) return B-> d-a-> d; if (a-> g! = B-> g) return B-> g-a-> g; if (a-> h! = B-> h) return B-> h-a-> h; if (a-> c! = B-> c) return a-> c-B-> c; char ta [50], tb [50]; strcpy (ta, a-> name ); strcpy (tb, B-> name); UTL (ta); UTL (tb); return strcmp (ta, tb);} int main () {char tName [105]; scanf ("% d", & n); getchar (); while (n --) {gets (tName); // gets () the function will absorb the last carriage return, but will not memset (team, 0, sizeof (team); scanf ("% d", & t); getchar (); for (int I = 0; I <t; I ++) gets (team [I]. name); scanf ("% d", & g); getchar (); while (g --) {char ch, a [50], B [50]; int x = 0, w, l; while (ch = getchar () {if ('#' = ch) break; a [x] = ch; x ++;} a [x] = '\ 0'; scanf ("% d", & w); // note that the score is less than 20 getchar (); scanf ("% d", & l); getchar (); gets (B); // find the ID int aa, bb; aa = find (a) of the team name ); bb = find (B); team [aa]. c + = 1; team [bb]. c + = 1; team [aa]. h + = w; team [bb]. h + = l; team [aa]. I + = l; team [bb]. I + = w; team [aa]. g = team [aa]. h-team [aa]. i; team [bb]. g = team [bb]. h-team [bb]. i; if (w> l) {team [aa]. B + = 3; team [aa]. d + = 1; team [bb]. f + = 1;} else if (w = l) {team [aa]. B + = 1; team [bb]. B + = 1; team [aa]. e + = 1; team [bb]. e + = 1;} else {team [bb]. B + = 3; team [bb]. d + = 1; team [aa]. f + = 1 ;}} qsort (team, t, sizeof (team [0]), cmp); printf ("% s \ n", tName ); for (int I = 0; I <t; I ++) {www.2cto.com printf ("% d) % s % dp, % dg (% d-% d), % dgd (% d-% d) \ n ", I + 1, team [I]. name, team [I]. b, team [I]. c, team [I]. d, team [I]. e, team [I]. f, team [I]. g, team [I]. h, team [I]. i);} if (n> 0) // note that the last line printf ("\ n") cannot be empty;} 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.