KillianMills

keymaker.cpp

Oct 2nd, 2014
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4.  
  5. using namespace std;
  6.  
  7. string keyMaker(string word, char character){ // makes a unique key based on the occurences of letters
  8.     string key;
  9.    
  10.     for(int i= 0; i < word.length(); i++){
  11.         if(word[i]== character){
  12.            
  13.             //key = key + i + "-" ; // - added each time letter is found
  14.             stringstream ss;
  15.             ss << i;
  16.            
  17.             key = key + "-" + ss.str();
  18.            
  19.         }
  20.     }
  21.    
  22.     return key;
  23. }
  24.  
  25. int main()
  26. {
  27.     while(true)
  28.     {
  29.         string w;
  30.         string k;
  31.         char guess;
  32.         cin >> w;
  33.         cin >> guess;
  34.        
  35.         k = keyMaker(w, guess);
  36.         cout << k <<endl;
  37.        
  38.     }
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment