Topic 1 (Amount of necessary storage)
- Enter some number, count the number. (No array required)
- Enter some numbers to find the maximum, minimum, and average values. (No array required)
- Enter some number, which is the closest two number. (Array required)
- Enter some numbers to find the second largest value. (No array required)
- Enter some numbers to ask for their variance. (Array required)
- Enter some number, statistics do not exceed the number of averages. (No array required)
Topic 2 (Number of statistical characters 1)
- MAXN settings are too large for the system to allocate such a large amount of memory.
- The judgment statement should be changed to if (s[i] = = ' 1 '), 1 is the value, ' 1 ' is the character.
- Use the Strlen function under the string.h header file, but this header file is not included.
Compiler will give warning warning:implicit declaration of function ' strlen '
- The for-loop judgment expression I < strlen (s) needs to call the Strlen function each time it is judged, resulting in a loss of efficiency.
The Modified program:
1#include <stdio.h>2#include <string.h>3 #defineN 655364 intMainvoid)5 {6 CharS[n];7scanf"%s", s);8 inttot =0, Len =strlen (s);9 for(inti =0; i < Len; i++)TenTot + = ('1'= = S[i])?1:0; Oneprintf"%d\n", tot); A return 0; -}
Exercise 3-1 Score (score)
1#include <stdio.h>2#include <string.h>3 intMainvoid)4 {5 intN;6 Chars[Bayi];7scanf"%d", &n);8 for(inti =0; I < n; i++) {9scanf"%s", s);Ten intsum =0, flag =0, Len =strlen (s); One for(intj =0; J < Len; J + +) { AFlag + = (S[j] = ='O') ?1: -Flag; -Sum + = (flag)? Flag:0; - } theprintf"%d\n", sum); - } - return 0; -}
Exercise 3-2 Molecular weight (Molar Mass)
Algorithmic Competition Primer Classic (second Edition)-chapter II Study questions and exercises