LINUX.ORG.RU

История изменений

Исправление pavlick, (текущая версия) :

#include <chrono>
#include <iostream>
#include <random>
#include <thread>
#include <array>
#include <vector>
#include <ncurses.h>
using namespace std;
using namespace chrono;

int main() {
	initscr();
	start_color();
	init_pair(1,COLOR_BLUE, COLOR_RED);
	random_device rd;
	mt19937 gen(rd());
	uniform_int_distribution<> distrib(2, 5);
	array<int, 5> delay;
	for (int &c : delay)
		c = distrib(gen);
	array<int, delay.size()> res;
	vector<int> input;
	input.reserve(10);
	for (int it = 0;  it < delay.size();  ++ it) {
		erase();
		bkgd(COLOR_PAIR(0));
		refresh();
		this_thread::sleep_for(seconds(delay[it]));
		bkgd(COLOR_PAIR(1));
		timeout(0);
		int key;
		while ((key = getch()) != ERR)
			input.push_back(key);
		timeout(-1);
		refresh();
		auto start = high_resolution_clock::now();
		input.push_back(getch());
		auto end = high_resolution_clock::now();
		res[it] = duration_cast<milliseconds>(end-start).count();
	}
	endwin();
	int av = 0;
	for (int c : res)
		av += c;
	cout << "average = " << av/res.size() << " msec\npressed = "
		<< input.size() << " keys" << endl;
}

В прошлом можно было читерить. 198 мсек, 5 нажатий. Скрин

sha256: 8e304b43095ec64824a17450969e58f189997b0cf19ba3e427d379eb7715873b

Исходная версия pavlick, :

#include <chrono>
#include <iostream>
#include <random>
#include <thread>
#include <array>
#include <vector>
#include <ncurses.h>
using namespace std;
using namespace chrono;

int main() {
	initscr();
	start_color();
	init_pair(1,COLOR_BLUE, COLOR_RED);
	random_device rd;
	mt19937 gen(rd());
	uniform_int_distribution<> distrib(2, 5);
	array<int, 5> delay;
	for (int &c : delay)
		c = distrib(gen);
	array<int, delay.size()> res;
	vector<int> input;
	input.reserve(10);
	for (int it = 0;  it < delay.size();  ++ it) {
		erase();
		bkgd(COLOR_PAIR(0));
		refresh();
		this_thread::sleep_for(seconds(delay[it]));
		bkgd(COLOR_PAIR(1));
		timeout(0);
		int key;
		while ((key = getch()) != ERR)
			input.push_back(key);
		timeout(-1);
		refresh();
		auto start = high_resolution_clock::now();
		input.push_back(getch());
		auto end = high_resolution_clock::now();
		res[it] = duration_cast<milliseconds>(end-start).count();
	}
	endwin();
	int av = 0;
	for (int c : res)
		av += c;
	cout << "average = " << av/res.size() << " msec\npressed = "
		<< input.size() << " keys" << endl;
}

В прошлом можно было читерить. 198 мсек, 5 нажатий. Скрин