Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. // ðàáîòà 1.cpp: îïðåäåëÿåò òî÷êó âõîäà äëÿ êîíñîëüíîãî ïðèëîæåíèÿ.
  2. //
  3.  
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string>
  7. #include <fstream>
  8. #include <iostream>
  9. #include <locale.h>
  10.  
  11. using namespace std;
  12.  
  13. bool isNumber(string s) {
  14. for (int i = 0; i < (int)s.size(); i++) {
  15. if (s[i] < '0' || s[i] > '9')
  16. return false;
  17. }
  18. return true;
  19. }
  20.  
  21. void InputNumber(int &NumbertoInput, string queryString = "", int max = -1) {
  22. if (queryString != "")
  23. printf("%s", queryString.c_str());
  24.  
  25. string input;
  26. getline(std::cin, input);
  27.  
  28. while (!isNumber(input) || input == "") {
  29. printf("Error...\n%s", queryString.c_str());
  30. getline(std::cin, input);
  31. }
  32. if (max == -1 || atoi(input.c_str()) < max)
  33. NumbertoInput = atoi(input.c_str());
  34. else {
  35. printf("Range error...\n");
  36. InputNumber(NumbertoInput, queryString, max);
  37. }
  38.  
  39. }
  40.  
  41. void InputString(string &StringToInput, string queryString = "") {
  42. if (queryString != "")
  43. printf("%s", queryString.c_str());
  44.  
  45. getline(std::cin, StringToInput);
  46.  
  47. return;
  48. }
  49.  
  50. void InputChar(char &c, string law, string queryString = "") {
  51. if (queryString != "")
  52. printf("%s", queryString.c_str());
  53.  
  54. string tmpInput;
  55.  
  56. InputString(tmpInput);
  57.  
  58. bool lawer = false;
  59.  
  60. while (!lawer) {
  61. while (tmpInput.size() != 1)
  62. InputString(tmpInput, "Error...\n" + queryString);
  63.  
  64. for (int i = 0; i < law.size(); i++) {
  65. if (law[i] == tmpInput[0]) {
  66. lawer = true;
  67. break;
  68. }
  69. }
  70. if (!lawer) {
  71. tmpInput = "qqqqqqqqqqqqqqqqqqq";
  72. printf("Wrong answer!\n");
  73. }
  74. }
  75.  
  76. c = tmpInput[0];
  77. }
  78.  
  79.  
  80. int main()
  81. {
  82. setlocale(LC_ALL, "Russian");
  83.  
  84. cout << "Uchenica gruppi" << endl;
  85. cout << "variant 23" << endl;
  86.  
  87. ifstream input("input.txt");
  88. ifstream text("text.txt");
  89. ofstream output("output.txt");
  90.  
  91. string s;
  92. getline(input, s);
  93. int count = 0;
  94. int k = 0;
  95. while (true)
  96. {
  97. string tmp;
  98. getline(text, tmp);
  99. if (tmp == "")
  100. break;
  101. for (int i = 0; i < strlen(tmp.c_str());)
  102. {
  103. k = 0;
  104. bool isf = false;
  105. if (tmp[i] == s[0])
  106. {
  107. for (int j = 0; j < strlen(s.c_str()); ++j)
  108. if (tmp[k++] != s[j])
  109. {
  110. isf = true;
  111. break;
  112. }
  113. if (!isf)
  114. ++count;
  115. i += strlen(s.c_str()) - 1;
  116. }
  117. else {
  118. ++i;
  119. }
  120. }
  121.  
  122.  
  123. }
  124.  
  125. output << "Count:" << count;
  126. cout << "Count:" << count << endl;
  127.  
  128.  
  129.  
  130. system("pause");
  131. return 0;
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement