Advertisement
Marini21

ICPC -Hangman v2

Nov 25th, 2014
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <list>
  4. using namespace std;
  5.  
  6. int main ()
  7. {
  8.     int round;
  9.  
  10.     while (cin >> round) {
  11.  
  12.         if (round == -1){
  13.             return 0;
  14.         }
  15.  
  16.         char solution [2000], guess [2000];
  17.  
  18.         cin >> solution;
  19.         cin >> guess;
  20.  
  21.         int length = strlen (solution);
  22.         list <char> l (&solution [0], &solution [length]);
  23.  
  24.         int stroke = 0;
  25.         length = strlen(guess);
  26.  
  27.         for (int i = 0; i < length; i++) {
  28.             if (!l.empty()){
  29.                 int tempSize = l.size ();
  30.                 l.remove (guess [i]);
  31.                 if (tempSize == l.size ()){
  32.                     stroke++;
  33.                 }
  34.             }
  35.             else{
  36.                 break;
  37.             }
  38.         }
  39.         cout << "Round " << round << endl;
  40.  
  41.         if (l.empty () && stroke < 7) {
  42.             cout << "You win." << endl;
  43.         }
  44.         else if (!l.empty () && stroke < 7) {
  45.             cout << "You chickened out." << endl;
  46.         }
  47.         else {
  48.             cout << "You lose." << endl;
  49.         }
  50.     }
  51.  
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement