Advertisement
makispaiktis

Lexarithm

Sep 13th, 2018 (edited)
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <map>
  4. #include <algorithm>
  5. #include <string>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11.  
  12.     // 1. Create the map
  13.     map <char,int> m;
  14.  
  15.     for(int i=0; i<10; i++){
  16.  
  17.         m.insert( pair <char,int> ('a' + i, i + 1) );
  18.     }
  19.  
  20.     for(int i=0; i<9; i++){
  21.  
  22.         m.insert( pair <char,int> ('k' + i, 10 * (i + 2)) );
  23.     }
  24.  
  25.     m.insert( pair <char,int> ('t',200) );
  26.  
  27.     for(int i=0; i<6; i++){
  28.  
  29.         m.insert( pair <char,int> ('u' + i, 100 * (i + 3)) );
  30.     }
  31.  
  32.     // 2. Show the content of map
  33.     map <char,int> :: iterator mitr;
  34.  
  35.     for(mitr=m.begin(); mitr!=m.end(); mitr++){
  36.  
  37.         cout << mitr->first << "    " << mitr->second << endl;
  38.     }
  39.  
  40.     // 3. Ask the user to give me a string
  41.  
  42.     cout << endl << "Give me your name to calculate your lexarithm." << endl;
  43.     string name;
  44.     cin >> name;
  45.  
  46.     vector <char> characters;
  47.  
  48.     for(int i=0; i<name.size(); i++){
  49.  
  50.         if(name[i] != '/0'){
  51.  
  52.             characters.push_back( name[i] );
  53.     }
  54.     }
  55.  
  56.     // 4. Show the content of vector
  57.     cout << endl;
  58.  
  59.     for(unsigned int i=0; i<characters.size(); i++){
  60.  
  61.         cout << characters[i] << " ";
  62.     }
  63.  
  64.     // 5. Find the characters in the map
  65.     cout << endl;
  66.  
  67.     int sum = 0;
  68.  
  69.     for(unsigned int i=0; i<characters.size(); i++){
  70.  
  71.         mitr = m.find(characters[i]);
  72.         cout << mitr->first << " = " << mitr->second << endl;
  73.         sum += mitr->second;
  74.  
  75.     }
  76.  
  77.     cout << endl << "So, lexarithm = " << sum << endl << endl;
  78.  
  79.     return 0;
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement