Advertisement
alin991

Untitled

Apr 24th, 2020
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <vector>
  4. #include <cstring>
  5. #include <time.h>
  6. #include <algorithm>
  7. using namespace std;
  8.  
  9. vector<string> mistake {"1","2","3","4","5","6","7"};
  10.  
  11. string generateword(){
  12. int wordindex;
  13. srand(time(NULL));
  14. vector<string> words;
  15. words = {"abruptlya", "boggle", "cycle", "juicy"};
  16. wordindex = rand()%words.size();
  17. return words[wordindex];
  18. }
  19. int* LetterintheWord(char letter, int &count,string S){
  20.  
  21. string word = S;
  22. int* indices = new int [500];
  23. memset (indices,-1,500);
  24. for (int i =0; i<word.size();i++){
  25. if (word[i]==letter){
  26. indices[count]= i;
  27. count++;
  28. }
  29. }
  30. return indices;
  31.  
  32. }
  33.  
  34. int TorF(char cha,string s){
  35. int count = 0;
  36. int* p = new int[500];
  37. p =LetterintheWord(cha, count,s);
  38. if (count == 0)
  39. return -1;
  40. else
  41. return 1;
  42. }
  43. void afiseazaLitere(string word){
  44. int finished=0;
  45. vector<int> v;
  46. int i=0;
  47. bool b;
  48. while(!finished){
  49. cout << "Type a letter";
  50. cout << endl;
  51. char c;
  52. cin >> c;
  53.  
  54. if(TorF(c,word)==-1){
  55. cout << mistake[i]<< endl;
  56. i++;
  57. }
  58. else{
  59. int count=0;
  60. int* vec=LetterintheWord(c,count,word);
  61. for(int i=0;i<count;i++){
  62. v.push_back(vec[i]);
  63. }
  64. b=0;
  65. for(int i=0;i<word.size();i++){
  66.  
  67. if(find(v.begin(),v.end(),i)!=v.end()){
  68. cout << word[i] << " ";
  69. }
  70. else{
  71. cout << "_ ";
  72. b=1;
  73. }
  74. }
  75. if(b==0)
  76. finished=1;
  77. }
  78.  
  79. if(i>=7)
  80. finished=1;
  81.  
  82.  
  83.  
  84. }
  85. if(finished&& b==0){
  86. cout << " Ai castigat";
  87. }
  88. }
  89.  
  90.  
  91. int main(){
  92. int count =0;
  93. string word=generateword();
  94. cout<<word<<"\n";
  95. afiseazaLitere(word);
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement