![:cry:](./images/smilies/icon_cry.gif)
could someone offer some I/O?
thanks
Moderator: Board moderators
Code: Select all
3
Team1
Team2
Team 3
3
Team1-Team2: 25-19 25-20 25-23
Team1-Team 3: 1-25 2-25 3-25
Team2-Team 3: 25-21 31-29 29-31 29-31 33-35
3
c
b
a
6
a-b: 25-19 25-20 25-23
b-a: 25-19 25-20 25-23
b-c: 25-19 25-20 25-23
c-a: 25-19 25-20 25-23
a-c: 25-19 25-20 25-23
c-b: 25-19 25-20 25-23
0
Code: Select all
Team 3 2 4 222
Team1 1 0 81
Team2 0 -4 209
a 2 0 274
b 2 0 274
c 2 0 274
I dont understand what u meant by score. However there are some test cases below...A team win a match if it has won 3 sets. There will at most 5 sets per match. There are no draws. A team wins a set if it has made 25 or more points and the other team is at least two points behind.
Code: Select all
3
Team1
Team2
Team 3
3
Team1-Team2: 25-23 24-20 22-25 10-30 12-90
Team1-Team 3: 1-25 2-25 3-25
Team2-Team 3: 25-21 31-29 29-31 29-31 33-35
3
c
b
a
6
a-b: 24-19 25-24 37-23 40-11 42-12
b-a: 25-19 25-20 25-24 11-25 11-29
b-c: 25-24 25-20 25-23 25-12 25-11
c-a: 25-26 25-27 27-23 30-11 35-12
a-c: 25-19 25-20 25-23
c-b: 25-19 25-20 25-23
0
Code: Select all
Team 3 2 4 222
Team2 1 1 335
Team1 0 -5 99
a 2 4 459
c 2 -2 369
b 1 -2 373
Code: Select all
solved :)
Code: Select all
int cmp(const void *a,const void *b)
{
ttt aa=*(ttt*)a,bb=*(ttt*)b;
if(aa.wm!=bb.wm)
return bb.wm-aa.wm;
if(aa.wp!=bb.wp)
return bb.wp-aa.wp;
if(aa.wm!=bb.wm) // got it!!! should be (aa.ws!=bb.ws)
return bb.ws-aa.ws;
return strcmp(aa.name,bb.name);
}
Code: Select all
3
Team1
Team2
Team 3
3
Team1-Team2 : 25-23 24-20 22-25 10-30 12-90
Team1-Team 3: 1-25 2-25 3-25
Team2-Team 3: 25-21 31-29 29-31 29-31 33-35
3
c
b
a
6
a - b : 24 - 19 25- 24 37-23 40-11 42-12
b-a : 25-19 25-20 25-24 11-25 11-29
b-c : 25-24 25-20 25-23 25-12 25-11
c-a:25-26 25-27 27-23 30-11 35-12
a-c:25-19 25-20 25-23
c-b:25-19 25-20 25-23
0
Code: Select all
/*
* safe input parsing. will always return the next integer from stdin if there is one.
* will disregard newlines, empty lines, spaces, tabs etc.
**/
int getinteger()
{
char row[10240];
do
{
gets(row);
char *p = row;
char foundint = 0;
while(*p != NULL)
{
if(*p >= '0' && *p <= '9')
{
foundint = 1;
break;
}
p++;
}
if(foundint == 1)
{
int d;
sscanf(row, "%d", &d);
return d;
}
} while(1);
}
/*
* safe input parsing. will always return the next line from stdin if there is one.
* will disregard newlines, empty lines, spaces, tabs etc.
**/
void getstring(char *t)
{
char row[10240];
do
{
gets(row);
char *p = row;
char foundstring = 0;
while(*p != NULL)
{
if((*p != ' ') && (*p != '\t') && (*p != '\n') && (*p != '\r'))
{
foundstring = 1;
break;
}
p++;
}
if(foundstring == 1)
{
strcpy(t, row);
return;
}
} while(1);
}
/*
* safe sscanf-style parsing of unsigned integers from a c-string
**/
void getintegers(char *row, int *nums, int &count)
{
count = 0;
int num1 = 0;
char hasnum = 0;
char *p = row;
while(*p != NULL)
{
if(*p >= '0' && *p <= '9')
num1 *= 10, num1 += (*p - '0'), hasnum = 1;
else {
if(hasnum == 1) {
//cout << num1 << endl;
nums[count++] = num1;
hasnum = 0;
}
num1 = 0;
}
p++;
}
if(hasnum == 1) {
//cout << num1 << endl;
nums[count++] = num1;
hasnum = 0;
}
}
/*
* safe white-space pruning. will remove spaces, tabs and newlines/carriage returns
* from the beginning and end of a c-string.
**/
void prunews(char *s)
{
char *i = s;
char *f = s;
char *p = s;
while(*p != NULL)
if((*p == ' ') || (*p == '\t') || (*p == '\r') || (*p == '\n'))
p++;
else
break;
while(*p != NULL)
*f++ = *p++;
*f = 0;
while(f != i)
if((*f == ' ') || (*f == '\t') || (*f == '\r') || (*f == '\n') || (*f == 0))
*f-- = 0;
else
break;
}
struct match {
int wins;
int loses;
int points;
int realwins;
int temp;
string name;
};
class comp
{
public:
int operator()(match a, match b)
{
if((a.realwins==b.realwins) && ((a.wins-a.loses)==(b.wins-b.loses)) && (a.points==b.points))
return strcmp(a.name.c_str(), b.name.c_str());
if((a.realwins==b.realwins) && ((a.wins-a.loses)==(b.wins-b.loses)))
return (a.points > b.points);
if(a.realwins==b.realwins)
return ((a.wins-a.loses) > (b.wins-b.loses));
return (a.realwins > b.realwins);
}
};
int main()
{
char row[10240];
int integers[5000];
match clear;
char printlinebreak = 0;
while(1)
{
clear.wins=clear.loses=clear.points=clear.realwins=clear.temp=0;
map<string,int> indexes;
vector<match> teams2;
int n = getinteger();
if(n == 0)
break;
// only print newline _between_ data sets.
if(printlinebreak == 1)
printf("\n");
printlinebreak = 1;
// parse teams
int t = n;
while(t--)
{
char team[64];
getstring(team);
prunews(team);
clear.name = team;
indexes[clear.name] = (int)teams2.size();
teams2.insert(teams2.end(), clear);
}
int x = getinteger();
int xn = x;
// parse results
while(xn--)
{
getstring(row);
char *p = row;
char team1[40], team2[40];
char *t;
t = team1; while(*p != '-') *t++ = *p++; p++; *t = 0;
t = team2; while(*p != ':') *t++ = *p++; p++; *t = 0;
prunews(team1);
prunews(team2);
int c = 0;
getintegers(p, integers, c);
int t1s = indexes[string(team1)];
int t2s = indexes[string(team2)];
for(int q = 0; q < c; q += 2)
{
int sa = integers[q], sb = integers[q+1];
//cout << sa << "-" << sb << endl;
teams2[t1s].points += sa;
teams2[t2s].points += sb;
if((sa >= 25) && (sb <= (sa - 2)))
{
teams2[t1s].wins++;
teams2[t1s].temp++;
teams2[t2s].loses++;
}
if((sb >= 25) && (sa <= (sb - 2)))
{
teams2[t2s].wins++;
teams2[t2s].temp++;
teams2[t1s].loses++;
//cout << teams2[t2s].temp << endl;
}
}
if(teams2[t1s].temp >= 3)
{
teams2[t1s].realwins++;
//teams2[t1s].temp = 0;
//teams2[t2s].temp = 0;
}
if(teams2[t2s].temp >= 3)
{
teams2[t2s].realwins++;
//teams2[t2s].temp = 0;
//teams2[t1s].temp = 0;
}
teams2[t1s].temp = 0;
teams2[t2s].temp = 0;
}
sort(teams2.begin(), teams2.end(), comp());
for(int i = 0; i < teams2.size(); i++)
printf("%-20s%5d%5d%10d\n", teams2[i].name.c_str(), teams2[i].realwins,
(teams2[i].wins - teams2[i].loses),
teams2[i].points);
}
return 0;
}
Code: Select all
3
c
b
a
6
a-b: 24-19 25-24 37-23 40-11 42-12
b-a: 25-19 25-20 25-24 11-25 11-29
b-c: 25-24 25-20 25-23 25-12 25-11
c-a: 25-26 25-27 27-23 30-11 35-12
a-c: 25-19 25-20 25-23
c-b: 25-19 25-20 25-23
0
Code: Select all
c-b: 25-19 25-20 25-23________
Your formation is correct. Did you consider this?Larry wrote:I use this for formatting:
"%-20s%5d%5d%10d\n"
Hope it helps.Output a blank line after each cup result