Advertisement
Guest User

Untitled

a guest
Dec 14th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <string>
  4. #include <set>
  5. #include <vector>
  6. using namespace std;
  7.  
  8. set<string> commands_set(string& commands) {
  9. commands = " " + commands;
  10. int commands_num = commands.size() / 3;
  11. string next_command;
  12. set<string> keys;
  13. while (commands.size() > 1) {
  14. next_command = commands.substr(1, 2);
  15. keys.insert(next_command);
  16. commands = commands.substr(3);
  17. }
  18. return keys;
  19. }
  20.  
  21. int main() {
  22. string commands;
  23. getline(cin, commands);
  24. set<string> keys = commands_set(commands);
  25. string str;
  26. int strings_num = 0;
  27. int symbols_num = 0;
  28. int max_length = 0;
  29. int words_num = 0;
  30. int tabs_num;
  31. while (getline(cin, str)) {
  32. strings_num++;
  33. symbols_num += str.size() + 1;
  34. if (str.size() > max_length) {
  35. max_length = str.size();
  36. }
  37. bool is_previos_alpha = false;
  38. for (char c : str) {
  39. if (isalpha(c)) {
  40. if (!is_previos_alpha) {
  41. words_num++;
  42. }
  43. is_previos_alpha = true;
  44. } else {
  45. is_previos_alpha = false;
  46. }
  47. }
  48. }
  49. bool is_first = true;
  50.  
  51. if (keys.find("-l") != keys.end()) {
  52. cout << strings_num;
  53. is_first = false;
  54. }
  55. if (keys.find("-w") != keys.end()) {
  56. if (!is_first) {
  57. cout << " ";
  58. }
  59. cout << words_num;
  60. is_first = false;
  61. }
  62. if (keys.find("-m") != keys.end()) {
  63. if (!is_first) {
  64. cout << " ";
  65. }
  66. cout << symbols_num;
  67. is_first = false;
  68. }
  69. if (keys.find("-L") != keys.end()) {
  70. if (!is_first) {
  71. cout << " ";
  72. }
  73. cout << max_length;
  74. is_first = false;
  75. }
  76. return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement