Advertisement
Marini21

ICPC -Hangman

Nov 24th, 2014
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. int main(){
  8.  
  9.     int round = 0;
  10.     int counter = 0;
  11.     int extraCounter = 0;
  12.     int lostCounter = 0;
  13.     bool found;
  14.     string tempSolution;
  15.     string tempGuess;
  16.  
  17.  
  18.     while (round != -1){
  19.         cin >> round;
  20.         if(round == -1){
  21.             break;
  22.         }
  23.         cin >> tempSolution;
  24.         cin >> tempGuess;
  25.  
  26.         vector <char> solution(tempSolution.begin(), tempSolution.end());
  27.         vector <char> guess(tempGuess.begin(), tempGuess.end());
  28.  
  29.         for (int i = 0; (unsigned)i < guess.size(); i++){
  30.             for (int k = 0; (unsigned)k < solution.size(); k++){
  31.                 if (guess[i] == solution[k]){
  32.                     counter++;
  33.                     found = true;
  34.                     for(int j = 0; (unsigned)j < solution.size() - k; j++){
  35.                         if(solution[k] == guess[k+j+i+1]){
  36.                             extraCounter++;
  37.  
  38.                         }
  39.                     }
  40.                 }
  41.             }
  42.             cout << "extra counter: " << extraCounter << endl;
  43.             if(!found){
  44.                 guess[i] =
  45.                 lostCounter++;
  46.             }
  47.             found = false;
  48.         }
  49.  
  50.         cout << "Round " << round << endl;
  51.  
  52.         if(lostCounter >= 7){
  53.             cout << "You lose." << endl;
  54.         }else if(lostCounter < 7 and (unsigned)counter < solution.size() + extraCounter) {
  55.             cout << "You chickened out." << endl;
  56.         }else if((unsigned)counter >= solution.size() + extraCounter){
  57.             cout << "You win." << endl;
  58.         }
  59.         counter = 0;
  60.         lostCounter = 0;
  61.         solution.clear();
  62.         guess.clear();
  63.     }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement