fork download
  1. #include <iostream>
  2. #include <fstream>
  3. #include <time.h>
  4. #include <vector>
  5. #include <string>
  6.  
  7. //#define DEBUG_MODE
  8.  
  9. using namespace std;
  10.  
  11. class type_text
  12. {
  13. public:
  14. type_text():
  15. is_EOF(0), is_newline(0)
  16. {}
  17.  
  18. vector<char>* string_vt;
  19. int is_EOF;
  20. int is_newline;
  21. };
  22.  
  23. class type_correctivity
  24. {
  25. public:
  26. type_correctivity():
  27. total_length(0), count_wrong(0)
  28. {}
  29.  
  30. int total_length;
  31. int count_wrong;
  32. };
  33.  
  34. type_text* print_string(ifstream& input_text)
  35. {
  36. type_text* text = new type_text();
  37.  
  38. char temp;
  39. text->string_vt = new vector<char>;
  40.  
  41. while (1)
  42. {
  43. temp = input_text.get();
  44.  
  45. if(temp == EOF)
  46. {
  47. text->is_EOF = 1;
  48. cout << endl << "==========================================" << endl;
  49. return text;
  50. }
  51. else if (temp == '\n')
  52. {
  53. text->is_newline = 1;
  54. cout << endl << "==========================================" << endl;
  55. return text;
  56. }
  57.  
  58. text->string_vt->push_back(temp);
  59. cout << temp;
  60. }
  61.  
  62. }
  63.  
  64. type_correctivity* check_correct(type_text* text, string* input_text)
  65. {
  66. type_correctivity* correct_rate = new type_correctivity();
  67. correct_rate->total_length = text->string_vt->size();
  68.  
  69. for(unsigned int vector_i = 0, i = 0 ; vector_i < text->string_vt->size() ; vector_i++, i++)
  70. {
  71. if(input_text->operator[](i) == NULL)
  72. {
  73. correct_rate->count_wrong += text->string_vt->size() - input_text->length();
  74. break;
  75. }
  76.  
  77. if (text->string_vt->operator[](vector_i) != input_text->operator[](i))
  78. correct_rate->count_wrong++;
  79. }
  80.  
  81. return correct_rate;
  82. }
  83.  
  84. int main(int argc, char** argv)
  85. {
  86. ifstream fin;
  87. type_text *input_text;
  88. type_correctivity* correct_rate;
  89. string test_text;
  90.  
  91. time_t start, end, total = 0;
  92.  
  93. int count_length = 0, count_wrong = 0;
  94.  
  95. char* check_text = new char[100];
  96.  
  97. if(argc == 1)
  98. {
  99. cout << "No file name parameter." << endl;
  100. fin.open("test.txt");
  101.  
  102. if(!fin)
  103. return 0;
  104.  
  105. while(1)
  106. {
  107. input_text = print_string(fin);
  108.  
  109. start = clock();
  110. getline(cin, test_text);
  111. end = clock();
  112.  
  113. cout << endl << "==========================================" << endl;
  114.  
  115. total += end - start;
  116.  
  117. correct_rate = check_correct(input_text, &test_text);
  118. count_length += correct_rate->total_length;
  119. count_wrong += correct_rate->count_wrong;
  120.  
  121. if(input_text->is_EOF == 1)
  122. break;
  123. }
  124.  
  125. cout << "Correct Rate : " << ( count_length - count_wrong ) / count_length * 100 << endl;
  126. cout << "Speed : " << (double)count_length / total * 1000 * 60 << " Types per minute." << endl;
  127.  
  128. #ifdef DEBUG_MODE
  129. cout << "### Debug Mode ###" << endl << correct_rate->count_wrong << endl << correct_rate->total_length << endl;
  130. #endif
  131. }
  132. else if(argc = 2)
  133. {
  134. fin.open(argv[1]);
  135.  
  136. if(!fin)
  137. return 0;
  138.  
  139. while(1)
  140. {
  141. input_text = print_string(fin);
  142.  
  143. start = clock();
  144. getline(cin, test_text);
  145. end = clock();
  146.  
  147. cout << endl << "==========================================" << endl;
  148.  
  149. total += end - start;
  150.  
  151. correct_rate = check_correct(input_text, &test_text);
  152. count_length += correct_rate->total_length;
  153. count_wrong += correct_rate->count_wrong;
  154.  
  155. if(input_text->is_EOF == 1)
  156. break;
  157. }
  158.  
  159. cout << "Correct Rate : " << ( count_length - count_wrong ) / count_length * 100 << endl;
  160. cout << "Speed : " << (double)count_length / total * 1000 * 60<< "Types per minute." << endl;
  161. }
  162. else if(argc > 2)
  163. {
  164. for(int arg_count = 1 ; arg_count < argc ; arg_count++)
  165. {
  166. fin.open(argv[arg_count]);
  167.  
  168. if(!fin)
  169. return 0;
  170.  
  171. while(1)
  172. {
  173. input_text = print_string(fin);
  174.  
  175. start = clock();
  176. getline(cin, test_text);
  177. end = clock();
  178.  
  179. cout << endl << "==========================================" << endl;
  180.  
  181. total += (end - start);
  182.  
  183. correct_rate = check_correct(input_text, &test_text);
  184. count_length += correct_rate->total_length;
  185. count_wrong += correct_rate->count_wrong;
  186.  
  187. if(input_text->is_EOF == 1)
  188. break;
  189. }
  190.  
  191. cout << "Correct Rate : " << ( count_length - count_wrong) / count_length * 100<< endl;
  192. cout << "Speed : " << (double)count_length / total * 1000 * 60 << "Types per minute." << endl;
  193.  
  194. cout << endl;
  195. }
  196. }
  197.  
  198. return 0;
  199. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
No file name parameter.