Advertisement
KillianMills

KeyTester2.cpp

Oct 2nd, 2014
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6.  
  7.  
  8. using namespace std;
  9.  
  10. string keyMaker(string word, char character){ // makes a unique key based on the occurences of letters
  11.     string key = "";
  12.    
  13.         for(int i=0; word[i]!=0; i++){
  14.         if(word[i]== character){
  15.             char *intStr = itoa(i);
  16.             string str = string(intStr);
  17.             key = key + str;
  18.            
  19.         /*string Result;          // string which will contain the result
  20.  
  21.         stringstream convert;   // stream used for the conversion
  22.  
  23.         convert << i;      // insert the textual representation of 'Number' in the characters in the stream
  24.  
  25.         Result = convert.str(); // set 'Result' to the contents of the stream
  26.        
  27.         key = key + Result;
  28.        
  29.         cout << key;
  30.         cout << Result;*/
  31.    
  32.         }
  33.     }
  34.    
  35.     return key;
  36. }
  37.  
  38. int main()
  39. {
  40.     while(true)
  41.     {
  42.         string w;
  43.         string key;
  44.         char guess;
  45.         cin >> w;
  46.         cin >> guess;
  47.        
  48.         key = keyMaker(w, guess);
  49.         cout << key<<endl;
  50.        
  51.     }
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement