Good job! :)
Maps are data structures which can be used to store (key, value)
pairs, where each key can be mapped to a corresponding value. Useful
for things like (Student ID, Student Name), (Name, Phone Number), or
for this example (Character, Frequency). They're also known as
dictionaries, associative arrays, hashtables, hashmaps, etc. depending
on what programming language you're using.
Here's a C++ example on using STL's map to compute the frequencies of
each character (remember to #include <map>).
string input = "adcBaDaDcdcdBcaccdaBe";
map<char, int> freq;
for (int i=0; i<input.length(); i++) {
freq[input[i]] = freq[input[i]] + 1;
}
...and to print out all (key, value) pairs...
map<char, int>::iterator it;
for (it=freq.begin(); it!=freq.end(); it++) {
cout << it->first << " => " << it->second << endl;
}
...resulting in the output:
B => 3
D => 2
a => 5
c => 6
d => 4
e => 1
Notice that the keys have been sorted for you. Very convenient for
your "Prime Frequency" problem :)
Read the C++ documentation or Google for more info.
Best,
J
> Finally, UVa accept my solution:D:D
> but exactly, my solution is not optimize, it is about 100 lines and I am
> sure it will not suitable solution.
>
> *today I found vectors are not good solutions for these cases.*