how fast can you type abc...z program?

Pages: 123
You were answered by R0mai when he linked to http://cplusplus.com/articles/how_to_ask/
@kyon

dutch ain't hard, but english is easier :)

(even though dutch is my native tongue :P


Edit:

You guys seriously type that fast? I have a 5.92 average =,=
it goes all great till i get to the wxyz... to scrambled =,=
Last edited on
Oh well, I decided to have a little fun.

Compiles for Windows and POSIX. Tested with GCC on XP and Linux.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// abc.cpp
//----------------------------------------------------------------------------
// Calculate the time it takes to type the ABC's.
//----------------------------------------------------------------------------

//          Copyright Michael Thomas Greer 2010
// Distributed under the Boost Software License, Version 1.0.
//    ( See accompanying file LICENSE_1_0.txt or copy at
//          http://www.boost.org/LICENSE_1_0.txt )

//----------------------------------------------------------------------------
// See http://www.cplusplus.com/forum/beginner/28855/

#include <ciso646>
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;

//----------------------------------------------------------------------------
typedef double epoch_time_t;

//----------------------------------------------------------------------------
#ifdef __WIN32__

  #include <windows.h>

  epoch_time_t get_epoch_time()  // Since 1601 Jan 1
    {
    FILETIME f;
    GetSystemTimeAsFileTime( &f );
    LARGE_INTEGER t =
      { {
      f.dwLowDateTime,
      f.dwHighDateTime
      } };
    return t.QuadPart / 10000000.0;  // 100 nano-second intervals
    }

  void waitforkeypress()
    {
    WaitForSingleObject(
      GetStdHandle( STD_INPUT_HANDLE ),
      INFINITE
      );
    }

//----------------------------------------------------------------------------
#else // POSIX

  #include <sys/time.h>

  epoch_time_t get_epoch_time()  // Since 1970 Jan 1
    {
    struct timeval tv;
    if (gettimeofday( &tv, NULL )) return 0.0;
    return tv.tv_sec + tv.tv_usec / 1000000.0;
    }

  #include <unistd.h>
  #include <termios.h>
  #include <poll.h>

  #define INFINITE (-1)

  void waitforkeypress()
    {
    struct termios initial_settings;
    tcgetattr( STDIN_FILENO, &initial_settings );

    struct termios settings = initial_settings;
    settings.c_lflag &= ~(ICANON);
    tcsetattr( STDIN_FILENO, TCSANOW, &settings );

    struct pollfd pls[ 1 ];
    pls[ 0 ].fd     = STDIN_FILENO;
    pls[ 0 ].events = POLLIN | POLLPRI;
    poll( pls, 1, INFINITE );

    tcsetattr( STDIN_FILENO, TCSANOW, &initial_settings );
    }

#endif

//----------------------------------------------------------------------------
const char* ABCS = "abcdefghijklmnopqrstuvwxyz";

//----------------------------------------------------------------------------
int main()
  {
  epoch_time_t start, stop;

  while (true)
    {
    string abcs;

    ios::sync_with_stdio( true );
    cout <<
      "Please enter the alphabet (in miniscules) as quickly as you can.\n"
      "You will be timed to see how long it takes.\n"
      "Begin when you are ready.\n\n"
      "> "
      << flush;

    waitforkeypress();
    start = get_epoch_time();
    getline( cin, abcs );
    stop = get_epoch_time();

    double time_spent = stop - start;

    unsigned minutes    = (unsigned) time_spent        / 60;
    unsigned seconds    = (unsigned) time_spent        % 60;
    unsigned hundredths = (unsigned)(time_spent * 100) % 100;

    cout << "It took you "
         << setfill( '0' ) << minutes    << ":"
         << setw( 2 )      << seconds    << "."
         << setw( 2 )      << hundredths;

    if (abcs == ABCS)
      {
      cout << ". Good job!\n";
      break;
      }

    cout << ", but you mistyped the alphabet.\n"
            "Would you like to try again ([y]/n)? "
         << flush;
    getline( cin, abcs );
    if (!abcs.empty() and (abcs[ 0 ] == 'n')) break;

    cout << "\n\n";
    }

  return 0;
  }

// end abc.cpp 

My best time yet is 0:05.25. Alas.

Please enter the alphabet (in miniscules) as quickly as you can.
You will be timed to see how long it takes.
Begin when you are ready.

> zyxwvutsrqponmlkjihgfedcba
It took you 0:06.73. Good job!

Process returned 0 (0x0)   execution time : 7.230 s
Press any key to continue.




Can anybody beat that?
My best time yet is 0:05.25. Alas.

duoas did (in normal order) ;)

Edit: 11.26 in reverse :)
Last edited on
Good grief!

My time (sans code modification):
> zyxwvutsrqponmlkjihgfedcba
It took you 0:10.51, but you mistyped the alphabet.
Would you like to try again ([y]/n)?


[edit] Oh yeah, this was 'cheating' because I could see wtf's backwards alphabet when I typed. Off the top of my head I can't do it.
Last edited on
@duoas:
How did you do this:
 
if (!abcs.empty() and (abcs[ 0 ] == 'n')) break;


I didn't think it was possible to create new overidable operators.
It is an operator synonym.
http://en.wikipedia.org/wiki/Ciso646
While the article states that inclusion of <ciso646> "has no effect, being empty" that is not necessarily true with all C++ compilers. Some require its inclusion to enable the operator keyword aliases. (Hence I always include it.)
I'm convinced QWERTY sucks.
Best times
forward -> 0:04.64
backward -> 0:06.73

I'm not going to train with that layout any more
Last edited on
Topic archived. No new replies allowed.
Pages: 123