[ create a new paste ] login | about

Link: http://codepad.org/Jfrwhsyi    [ raw code | output | fork ]

C++, pasted on Oct 11:
#include <iostream>
#include <array>
#include <string>
#include <ctime>
#include <cstdlib>
#include <algorithm>

using namespace std;


bool open_char(const string& s, string& temp, string& ch, int& shtraf) {

	if (ch == "0") {
		shtraf = 10;
		return false;
	}
	bool flag = true;

	if (s.length() > 1 && s == ch) {
		return true;
	}
	else if (ch.length() == 1) {
		for (size_t i = 0; i < s.length(); i++) {
			if (s[i] == ch[0]) {
				temp[i] = ch[0];
				flag = false;
			}
		}
	}
	if (flag) shtraf++;
	bool open = false;


	return open = temp == s;
}

bool ugadaika(const string &s, string &temp, int& shtraf) {
	if (shtraf > 9) return false;

	cout << temp << "\tSHTRAF == " << shtraf << "\n";
	string my_word;
	getline(cin, my_word);

	if (!open_char(s, temp, my_word, shtraf)) {
		ugadaika(s, temp, shtraf);
	}
	else {
		shtraf -= 5;
		if (shtraf < 0) shtraf = 0;
		cout << "word is open!!!   (" << s << ")\n";
	}
	return true;
}

void replace_str(string&s, const char& ch = '.') { for (size_t i = 0; i < s.length(); i++) s[i] = ch; }

bool get_word(const string& word, string temp, int &shtraf) {

	if (temp.empty()) {
		temp = word;
		replace_str(temp);
	}
	if (shtraf > 9) return false;
	return ugadaika(word, temp, shtraf);
}

int main() {
	srand(time(0));
	int num_word = rand() % 20;

	array<string, 20> a{
		"arbuz","moskwa","reka","pila","dom",
		"gore","luk","mahina","palma","sila",
		"lampa","sok","sufle","begemot","znak",
		"polotno","molot","lopata","grib","son"
	};

	random_shuffle(a.begin(), a.end());

	size_t i = 0;
	int shtraf = 0;
	string temp;

	while (i < 20 && shtraf < 10) {
		cout << "progress " << i + 1 << "//" << 20 << "\n";
		get_word(a[i], temp, shtraf);
		cout << "\n===============================\n\n";
		i++;
	}

	if (i == 20) {
		cout << "POZDRAVLAEM!!!! ALL WORDS OPENED!!!!\n";
	}
	else {
		cout << "WORDS OPENED " << i - 1 << " GAME OVER\n";
	}
	system("PAUSE");
}


Output:
1
2
3
4
Line 16: error: array: No such file or directory
In function 'int main()':
Line 71: error: 'array' was not declared in this scope
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: