Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <vector>
- #include <cstring>
- #include <time.h>
- #include <algorithm>
- using namespace std;
- vector<string> mistake {"1","2","3","4","5","6","7"};
- string generateword(){
- int wordindex;
- srand(time(NULL));
- vector<string> words;
- words = {"abruptlya", "boggle", "cycle", "juicy"};
- wordindex = rand()%words.size();
- return words[wordindex];
- }
- int* LetterintheWord(char letter, int &count,string S){
- string word = S;
- int* indices = new int [500];
- memset (indices,-1,500);
- for (int i =0; i<word.size();i++){
- if (word[i]==letter){
- indices[count]= i;
- count++;
- }
- }
- return indices;
- }
- int TorF(char cha,string s){
- int count = 0;
- int* p = new int[500];
- p =LetterintheWord(cha, count,s);
- if (count == 0)
- return -1;
- else
- return 1;
- }
- void afiseazaLitere(string word){
- int finished=0;
- vector<int> v;
- int i=0;
- bool b;
- while(!finished){
- cout << "Type a letter";
- cout << endl;
- char c;
- cin >> c;
- if(TorF(c,word)==-1){
- cout << mistake[i]<< endl;
- i++;
- }
- else{
- int count=0;
- int* vec=LetterintheWord(c,count,word);
- for(int i=0;i<count;i++){
- v.push_back(vec[i]);
- }
- b=0;
- for(int i=0;i<word.size();i++){
- if(find(v.begin(),v.end(),i)!=v.end()){
- cout << word[i] << " ";
- }
- else{
- cout << "_ ";
- b=1;
- }
- }
- if(b==0)
- finished=1;
- }
- if(i>=7)
- finished=1;
- }
- if(finished&& b==0){
- cout << " Ai castigat";
- }
- }
- int main(){
- int count =0;
- string word=generateword();
- cout<<word<<"\n";
- afiseazaLitere(word);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement