Best YouTuber

Problem Statement

Your program is given a list of NN thought-provoking YouTube videos. Each video has a creator (with name length SS) and a number of likes (II). (They don’t, however, have any dislikes because YouTube removed the dislike button. 😢)

Your task is to print out the YouTuber from among those videos with the best likes-to-videos ratio, along with their video count and total number of likes to prove it. They are thusly crowned the best YouTuber!

A YouTuber’s likes-to-videos ratio is calculated by their total likestheir number of videos\frac{\text{their total likes}}{\text{their number of videos}}.

If there is a tie, print that there's no best YouTuber.

Input Format

Each line of input should be in the format [video creator], [video likes] (note the separating comma).

Example Input

Wild Candy, 84317
Logan Paul, 9185
Wild Candy, 20097
Jaden Smith, 35664
Wild Candy, 15321
Logan Paul, 75820

The provided starter code converts this into a linked list similar to the following.

image

Constraints

For all test cases,

  • 1≤N≤1,0001 \le N \le 1,000
  • 1≤S≤1281 \le S \le 128
  • 0≤I≤2,000,0000 \le I \le 2,000,000.

There is no need to mitigate floating-point errors.

Output Format

[YouTuber name] is the best YouTuber.
Number of videos: [their number of videos]
Total likes: [their total likes]

Example Output

Logan Paul is the best YouTuber.
Number of videos: 2
Total likes: 85005

Sample Input 0

Wild Candy, 84317
Logan Paul, 9185
Wild Candy, 20097
Jaden Smith, 35664
Wild Candy, 15321
Logan Paul, 75820

Sample Output 0

Logan Paul is the best YouTuber.
Number of videos: 2
Total likes: 85005

Explanation 0

There are three YouTubers found from among the given videos: Wild Candy, Logan Paul, and Jaden Smith. Calculating each of their likes-to-videos ratios gives 39,911.6˙39,911.\dot{6}, 42,502.542,502.5, and 35,66435,664, respectively.

As Logan Paul has the greatest likes-to-videos ratio, he's the best YouTuber.

Sample Input 1

Will Smith, 2000
Logan Paul, 2000
Will Smith, 2000

Sample Output 1

It's a tie! There is no best YouTuber.

Starter Code

// A program that constructs a list of YouTube videos from input.
// TODO: It then prints the YouTuber from among those videos with the greatest
// likes-to-video ratio.
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#define BUFFER_SIZE 128
struct video {
char creator[BUFFER_SIZE];
int likes;
struct video *next;
};
// provided functions
struct video *populate_video_list_from_input(void);
struct video *create_video(char *creator, int likes);
void print_all_videos(struct video *head);
int main() {
/* Read input from STDIN. */
struct video *head_video = populate_video_list_from_input();
// print_all_videos(head_video);
/* Enter your code here. Print output to STDOUT. */
return 0;
}
// provided functions
struct video *populate_video_list_from_input(void) {
struct video *head_video = NULL;
struct video *current_video = NULL;
char input_line[BUFFER_SIZE];
while (fgets(input_line, BUFFER_SIZE, stdin) != NULL) {
char creator[BUFFER_SIZE];
int likes;
sscanf(input_line, "%[^,],%d", creator, &likes);
if (head_video == NULL) {
head_video = create_video(creator, likes);
current_video = head_video;
} else {
current_video->next = create_video(creator, likes);
current_video = current_video->next;
}
}
return head_video;
}
struct video *create_video(char *creator, int likes) {
struct video *new_video = malloc(sizeof(struct video));
strcpy(new_video->creator, creator);
new_video->likes = likes;
new_video->next = NULL;
return new_video;
}
void print_all_videos(struct video *head) {
int i = 0;
struct video *current = head;
while (current != NULL) {
printf(
"video_%d = {\n"
" creator: \"%s\",\n"
" likes: %d\n"
"}",
i,
current->creator,
current->likes
);
if (current->next != NULL) {
printf(",");
}
printf("\n");
i++;
current = current->next;
}
}