两道C语言作业,急!请大侠帮忙!谢谢

来源:百度知道 编辑:UC知道 时间:2024/05/14 05:58:50
1.Tell me the frequencies
Given a line of text you will have to find out the frequencies of the ASCII
characters present in it. The given lines will contain none of the first 32
or last 128 ASCII characters. Of course lines may end with ‘\n’ and ‘\r’
but always keep those out of consideration.

Input

Several lines of text are given as input. Each line of text is considered as
a single input. Maximum length of each line is 1000.

Output

Print the ASCII value of the ASCII characters which are present and their
frequency according to the given format below. A blank line should separate
each set of output. Print the ASCII characters in the ascending order of
their frequencies. If two characters are present the same time print the
information of the ASCII character with higher ASCII value first. Input is
terminated by end of file.

Sample Input:

AAABBC
12233

只给出方法,具体代码还是自己写。

第一题用个0到127的数组,里面存储ASC码值及计数值的结构。计数再排序就简单实现了。
对每一行的算法思路是:
数组计数清0,ASC码值设为下标;
读字符,把字符对应的下标处加1计数;
按计数值排序;
输出计数值非0的ASC码值和计算值。

第二题条件不够,原题有公式∑i * A^i,你没有给出。我在
http://acm.uva.es/p/v105/10523.html
找到了原题。
∑i * A^i是有公式解的,可以直接代公式(别告诉我你不会推,对∑x^i逐项微分就看出来了)。当然也可以一项一项用笨办法算,倒省心。
如果作业对运行时间要求高的话,也可以慢慢用笨办法算出来,打个表交作业。

大哥 你的英文实在太好了 我费半天劲才大概看明白第一题 第一题你需要用结构体的 而且是结构体数组 写的话比较麻烦 我这没有VC 主要思路就是定义一个结构体类型 包含一个可以装ASC码的整型,还有一个可以计数的整型.在主函数定义数组时要定义结构体数组 这样这个程序的大部分问题就已经解决了.剩下的你来完成.用一个字符数组来装载输入的语句,然后FOR函数移动"指针"判断每个字符的ASC码 计数 等等~

虽然想帮你,本人英文一向很烂,把题目翻成中文先吧,实在看得很不爽~~

不好意思我英语太烂了看不懂~~~