有问题想求解,自己想不出来了
问题1;我自己输入字母,每次输入一个,总共可以输入20次,然后最后输出的是出现平率最高的字母和它出现的次数。比如说我输入了三次q,其他的都不是重复的字母。然后输出结果是:most frequent letter: q,3times. 这种。
具体问题是:Create a one-dimensional array to read 20 alphabetical letters (your program should be able to detect
and print out an error message if a non-alphabetical letter is inputted). As each letter is entered, print a
message saying ‘duplicate letter’ if the letter is already in the array. Write a function that can sort the
array after all 20 letters have been entered. Write another function that print out the most frequent letter
and number of time it was entered. Prepare for the case where all 20 letters are different, or all are the
same.
问题二我自己想了半天也想不出来了:
A survey to know the popularity of four sports (Cricket, Footy, Tennis and Soccer) was
conducted in four cities (Melbourne, Sydney, Brisbane and Adelaide). Each person surveyed
was asked to give his city and the name of his favorite sports. The results, in coded form, are
tabulated as follows:
M 1 S 2 B 1 B 3 M 2 B 4
S 1 A 3 M 4 B 2 B 1 S 3
B 4 B 4 M 1 M 1 B 3 B 3
S 1 S 1 S 2 M 4 M 4 S 2
A 1 S 2 B 3 M 1 B 1 S 2
A 3 M 4 S 1 B 2 M 3 B 4
Codes represent the following information:
M - Melbourne 1 - Cricket
S – Sydney 2 - Footy
B – Brisbane 3 - Tennis
A – Adelaide 4 - Soccer
Write a program to produce a table showing popularity of various sports in four cities.
A two-dimensional array frequency is used as an accumulator to store the number of particular
sports in each city. For example, the element frequency [i][j] denotes the number of a
particular sport j in city i. The frequency is declared as an array of size 5x5 and all the elements
are initialized to zero
Sample Output
For each entry, enter the city code
followed by the sport code.
Enter the letter X to indicate end.
M 1 S 2 B 1 B 3 M 2 B 4
S 1 A 3 M 4 B 2 B 1 S 3
B 4 B 4 M 1 M 1 B 3 B 3
S 1 S 1 S 2 M 4 M 4 S 2
A 1 S 2 B 3 M 1 B 1 S 2
A 3 M 4 S 1 B 2 M 3 B 4 X
POPULARITY TABLE
----------------------------------------------------
City Cricket Footy Tennis Soccer
-----------------------------------------------------
Melbourne 4 1 1 4
Sydney 4 5 1 0
Brisbane 2 2 4 4
Adelaide 1 0 2 0
-----------------------------------------------------
[此贴子已经被作者于2017-5-18 23:29编辑过]