Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <map>
- #include <algorithm>
- #include <string>
- using namespace std;
- int main()
- {
- // 1. Create the map
- map <char,int> m;
- for(int i=0; i<10; i++){
- m.insert( pair <char,int> ('a' + i, i + 1) );
- }
- for(int i=0; i<9; i++){
- m.insert( pair <char,int> ('k' + i, 10 * (i + 2)) );
- }
- m.insert( pair <char,int> ('t',200) );
- for(int i=0; i<6; i++){
- m.insert( pair <char,int> ('u' + i, 100 * (i + 3)) );
- }
- // 2. Show the content of map
- map <char,int> :: iterator mitr;
- for(mitr=m.begin(); mitr!=m.end(); mitr++){
- cout << mitr->first << " " << mitr->second << endl;
- }
- // 3. Ask the user to give me a string
- cout << endl << "Give me your name to calculate your lexarithm." << endl;
- string name;
- cin >> name;
- vector <char> characters;
- for(int i=0; i<name.size(); i++){
- if(name[i] != '/0'){
- characters.push_back( name[i] );
- }
- }
- // 4. Show the content of vector
- cout << endl;
- for(unsigned int i=0; i<characters.size(); i++){
- cout << characters[i] << " ";
- }
- // 5. Find the characters in the map
- cout << endl;
- int sum = 0;
- for(unsigned int i=0; i<characters.size(); i++){
- mitr = m.find(characters[i]);
- cout << mitr->first << " = " << mitr->second << endl;
- sum += mitr->second;
- }
- cout << endl << "So, lexarithm = " << sum << endl << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement