Series Team Score
Two soccer teams A and B play a series of matches over a period of time. In a match, the winning team gets 3 points. If the match ends in a tie (draw) with both teams scoring same goals, then both the teams get one point each. The losing team does not get any point.
The program must accept the goals scored by both team A and B in certain number of matches and print the cumulative scores of team A and B separated by a space.
Input Format:
First line will contain the goals scored by team A, with the goal values separated by a space.
Second line will contain the goals scored by team B, with the goal values separated by a space.
Output Format:
First line will contain the scores of team A and B separated by a space.
Boundary Conditions:
The length of the input with the space separated goals is from 3 to 100.
Example Input/Output 1:
Input:
3 5 1
3 2 0
Output:
7 1
Explanation:
Team A drew the first match and hence both team A and B got one point each.
Team A won both matches two and three and hence got additional 6 points.
So the final score of team A is 7 and team B is 1.
#include<stdio.h>
#include <stdlib.h>
int main(void)
{ char *str,*str1;
scanf("%[^\n]s",str);
scanf("%[^\n]s",str1);
char *end = str;
char *end1=str1;
int x[100],y[100];
int o=0,p=0;
while(*end) {
int n = strtol(str, &end, 10);
x[o]=n;
o++;
while (*end == ' ')
{ end++;
} str = end;
}
while(*end)
{int n=strtol(str1,&end1,10);
y[p]=n;p++;
while(*end1==' ')
{end1++;
}str1=end1;
}int r=0,e=0;
for(int i=0,j=0;i<=o&&j<=p;i++,j++)
{ if(x[o]==y[p])
{ r++; e++; }
else if(x[o]>y[p])
{ r+=3; }
else if(x[o]<y[p])
{ e+=3; }
}
printf("%d %d",r,e);
return 0;
}
Comments
Post a Comment