ozimas

PO zad. 3.1

Jan 20th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.48 KB | None | 0 0
  1. #include "stdafx.h"  
  2. #include <iostream>
  3. #include <stdlib.h>  
  4. #include <string.h>  
  5. #include <Windows.h>  
  6. #include <process.h>    
  7.  
  8. char alfabet[] = "abcd";
  9. char bufor[100];
  10. int n = 4;
  11.  
  12. int L = strlen(alfabet);
  13. bool czywbuf = false;
  14. bool odgadnieto = false;
  15. bool kendprac = false;
  16. char haslouzytk[100] = "acba";
  17. void haslogen(int n, int L, int level, char * alfabet, char * bufor)
  18. {
  19.     if (level == n)
  20.     {
  21.         bufor[level] = 0;
  22.         czywbuf = true;
  23.         printf("%s\n", bufor);
  24.         while (czywbuf == true)  {}
  25.         if (odgadnieto == true)  { _endthread(); }
  26.     }
  27.     else {
  28.         for (int i = 0; i<L; i++)
  29.         {
  30.             bufor[level] = alfabet[i];  haslogen(n, L, level + 1, alfabet, bufor);
  31.         }
  32.     }
  33. }
  34. void generuj_haslo(void * Args)
  35. {
  36.     haslogen(n, L, 0, alfabet, bufor);
  37.     kendprac = true;  _endthread();
  38. }
  39. void sprawdz_poprawnosc_hasla(void * Args)
  40. {
  41.     while (odgadnieto == false && kendprac == false)
  42.     {
  43.         if (czywbuf == true)
  44.         {
  45.             if (strcmp(haslouzytk, bufor) == 0)
  46.             {
  47.                 printf("Znaleziono haslo\n");
  48.                 czywbuf = false;
  49.                 odgadnieto = true;
  50.             }
  51.             else  { czywbuf = false; }
  52.         }
  53.     }
  54.     if (kendprac == true)
  55.     {
  56.         printf("Nie odnaleziono hasla\n");
  57.     }  _endthread();
  58. }
  59.  
  60. int _tmain(int argc, _TCHAR* argv[])
  61. {
  62.     HANDLE producent = (HANDLE)_beginthread(generuj_haslo, 0, NULL);
  63.     HANDLE konsument = (HANDLE)_beginthread(sprawdz_poprawnosc_hasla, 0, NULL);
  64.     WaitForSingleObject(producent, INFINITE);
  65.     WaitForSingleObject(konsument, INFINITE);
  66.     system("pause");
  67.     return 0;
  68. }
Add Comment
Please, Sign In to add comment