Advertisement
juanjo12x

UVA_489_Hangman_Judges

Jul 28th, 2014
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <cstring>
  5. #include <iostream>
  6. #include <cstdio>
  7. #include <algorithm>
  8. #include <cstring>
  9. #include <string>
  10. #include <cctype>
  11. #include <stack>
  12. #include <queue>
  13. #include <list>
  14. #include <vector>
  15. #include <map>
  16. #include <set>
  17. #include <sstream>
  18. #include <stdlib.h>
  19. #include <cmath>
  20. #define LL unsigned long long
  21. using namespace std;
  22. bool isfull(int full[],int n){
  23.  for(int i=0;i<n;i++){
  24.     if(full[i]==0) return false;
  25.  }
  26.  return true;
  27. }
  28. /*funcion que verifica que existe dicho elemento ya antes*/
  29. bool existe(char guess[],int k){
  30.     for (int i=0;i<k;i++){
  31.         if(guess[i]==guess[k]) return true;
  32.     }
  33.     return false;
  34. }
  35. int main() {
  36.     int round,n,n1,hang;char key[1000];char guess[1000];bool found;
  37.  
  38.     while(scanf("%d",&round)){
  39.         if(round==-1) break;
  40.         cin>>key;
  41.         cin>>guess;
  42.         hang=0;
  43.         n=strlen(key);n1=strlen(guess);
  44.         int full[n];
  45.         /*inicializo el arreglo de booleanos*/
  46.         memset(full, 0, sizeof(int) * n);
  47.         for (int i=0;i<n1;i++){
  48.             found=false;/*inicializo found*/
  49.             for (int j=0;j<n;j++){
  50.              if(guess[i]==key[j]){
  51.                 full[j]=1;/*para cada posicion encontrada*/
  52.                 found=true;
  53.  
  54.              }
  55.             }
  56.             if(!found && (!(existe(guess,i)))) hang++;/*si no encontro para ninguna posicion*/
  57.                         if(hang==7) break;
  58.            if(isfull(full,n)) break;
  59.         }
  60.         printf("Round %d\n",round);
  61.         if (isfull(full,n)) printf("You win.\n");
  62.         else if(hang==7) printf("You lose.\n");
  63.         else if(hang<7) printf("You chickened out.\n");
  64.     }
  65.  
  66.     return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement