Algorithmic competition Getting Started classic exercise 3-1 score statistics Exercise 3-2 the length of a word

Source: Internet
Author: User

Exercise 3-1 Score Statistics

Enter some student's score, which score appears the most times? If there are multiple parallel, from small to large output.
Task 1: Non-negative integers with fractions not exceeding 100
Task 2: The score does not exceed 100 of the nonnegative real number, but retains a maximum of two decimal places.

Task 1

#include <stdio.h> #include <stdlib.h> #include <string.h> #define MAXN 101 + 10int a[maxn];int Main (int ARGC, Char *argv[]) {    int n, max = 0, I;  memset (A, 0, sizeof (a));  while (scanf ("%d", &n) = = 1)  {     a[n]++;     if (A[n] > max) max = A[n];  }  for (i = 0; I <=; i++)  {     if (a[i] = = max) printf ("%d", I);  }  printf ("\ n");  memset (A, 0, sizeof (a));  System ("PAUSE");  return 0;}

Task 2

#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #define MAXN 10001 + 10int a[maxn];int Main (int argc, char *argv[]) {  double degree, m;  int max = 0, I;  memset (A, 0, sizeof (a));  while (scanf ("%lf", °ree) = = 1)  {     double m = degree*100;     int n;     n = Floor (m+0.5);     a[n]++;     if (A[n] > max) max = A[n];  }  for (i = 0; I <= 10000; i++)  {     if (a[i] = = max) printf ("%.2lf", i*0.01);  }  printf ("\ n");   System ("PAUSE");  return 0;}

Summary: Task 2 degree set to double, then to int, with floor (m+0.5), previously encountered, remember


Exercise 3-2 The length of the word

The average length of their output. Words contain only uppercase and lowercase letters, separated by one or more spaces.


#include <stdio.h> #include <stdlib.h> #include <string.h> #define MAXN 100char a[maxn];int Main (int ARGC, Char *argv[]) {  int count = 0;  float sum = 0;  while (scanf ("%s", a) = = 1)  {     count++;     Sum + = strlen (a);  }    printf ("%.3lf\n", sum/count);  System ("PAUSE");  return 0;}

Summary: Do not know the other answers on the Internet why write so many code, there is time to take a closer look

Algorithmic competition Getting Started classic exercise 3-1 score statistics Exercise 3-2 the length of a word

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.