Home > Back-end >  Hduoj examination rank
Hduoj examination rank

Time:12-01

Just started to write the one side, or a hard, just don't know where is wrong, then changed the redefinition of the time, the results directly added to the time, was too?
I ask you is this why?
 
#include

using namespace std;
Typedef long long ll;

Struct node {
Char name [15].
Int num=0;
Int time;//an uninitialized
};

Bool CMP (node a and node b) {
If (a.n um!=b.n um) return a.n um & gt; B.n um.
The else {
If (a.t ime!=b.t ime) return a.t ime & lt; B.t ime.
The else return STRCMP (a.n ame, b.n ame) & lt; 0;
}
}

Int main ()
{
Int n, m;
The scanf (" % d % d ", & amp; N, & amp; m);
Struct node student [1000].
Int I=0, passtime, wrong;
While (the scanf (" % s ", & amp; Student [I] name)! EOF)={
For (int j=0; J & lt; n; J++) {
Wrong=0;
The scanf (" % d, % d) ", & amp; Passtime, & amp; Wrong);
If (passtime & gt; 0 {
Student [I] num++;
Student [I]. Time=passtime + m * wrong;//the value assigned to direct time
}
}
i++;
}
Sort (student, student + I, CMP);
For (int j=0; J & lt; i; J++) {
- 10 printf (" % s % 2 d % 4 d \ n ", student [j]. Name, student [j]. Journal of num, student [j]. Journal of time).
}
return 0;
}


Changed after they come here, speechless,
 # include 

using namespace std;
Typedef long long ll;

Struct node {
Char name [15].
Int num=0;
Int time=0;
};

Bool CMP (node a and node b) {
If (a.n um!=b.n um) return a.n um & gt; B.n um.
The else {
If (a.t ime!=b.t ime) return a.t ime & lt; B.t ime.
The else return STRCMP (a.n ame, b.n ame) & lt; 0;
}
}

Int main ()
{
Int n, m;
The scanf (" % d % d ", & amp; N, & amp; m);
Struct node student [1000].
Int I=0, passtime, wrong;
While (the scanf (" % s ", & amp; Student [I] name)! EOF)={
For (int j=0; J & lt; n; J++) {
Wrong=0;
The scanf (" % d, % d) ", & amp; Passtime, & amp; Wrong);
If (passtime & gt; 0 {
Student [I] num++;
Student [I] time +=passtime + m * wrong;
}
}
i++;
}
Sort (student, student + I, CMP);
For (int j=0; J & lt; i; J++) {
- 10 printf (" % s % 2 d % 4 d \ n ", student [j]. Name, student [j]. Journal of num, student [j]. Journal of time).
}
return 0;
}


Everybody look!

CodePudding user response:

What kind of change before is?
In addition, if the int time;//an uninitialized is this kind of situation, if the if (passtime & gt; {0) not to enter the if, then student [I]. Time=passtime + m * wrong;//the value assigned to the time, there is no chance to assignment, student [I]. Time is spam, your com comparison results is not necessarily accurate

CodePudding user response:

The code above is changed before, below is the change after, change where the two annotations, other the same, the code is no problem, don't know if it involves the knowledge of c language variable memory assignment?
  • Related