求解C++语言

来源:百度知道 编辑:UC知道 时间:2024/07/04 08:09:00
2. Two phrases or sentences are said to be anagrams of each
other if every alphabet appears the same number of times in
the two strings. (Ignore all characters other than alphabets.
Comparisons are case-insensitive.) Examples of two strings
that are anagrams of each other are shown in the table to the
right.
exam[le:
# String 1 String 2
1 "O, Draconian devil!" "Leonardo da Vinci!"
2 "Oh, lame saint!" "The Mona Lisa!"
3 "Mother-in-law" "Woman Hitler"
Write a program that takes two phrases/sentences as input
and computes if the two strings are anagrams of each other
or not. Call this program anagram.c.
3. Write a program that arranges a set of given words in alphabetical order. The words are given in a file called
input-words.txt. The output is written to file output-words.txt. Assume that the input and output files contains
one word per line.
E

第一个是达芬奇密码裏的东东啊。。先冏一下。。

我就说说思路吧:

第一个可以定义两个input string,一个字母一个字母地把两个input读进来。
同时定义两个int 的array,长度为26,初始化为全0,每读一个字母,就把对应字母,如A,a对应的是1,etc,在原来的基础上加1。

这样把两个string 都读完后,得到两个array,对其进行比较,就行了。

第二个可以用和第一个类似的处理方法,也是通过将字母转化为一个对应的int array,再通过比较 array中的元素来进行排序。

两个题其实还可以通过ASIIC来进行操作,不过因为涉及大小写的输入,比较麻烦。

晕,好像有两个一样的题。。