Advertisement
Guest User

Untitled

a guest
Oct 12th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #include<cmath>
  4. #include<exception>
  5.  
  6.  
  7.  
  8. using namespace std;
  9.  
  10.  
  11. int main() {
  12. char line[1000];
  13. string sline;
  14. int wlength[100];
  15. int wcount = 0, lcount, i, scount, sentc = 0;//broi izr
  16. bool sword = false, start = true, strict = false;
  17. do {
  18. cin.getline(line, 1000, '\n');
  19. sline = line;
  20. if (start && sline == "strict") {
  21. scount = 0; strict = true;
  22. continue;
  23. }
  24. for (i = 0; i < sline.length(); i++){
  25. if ((sline[i] >= 'a' && sline[i] <= 'z') || (sline[i] >= 'A' && sline[i] <= 'Z'))
  26. {
  27. if (i == 0 || !sword) {
  28. sword = true;
  29. lcount = 1;
  30. }
  31. else {
  32. if (sword){
  33. lcount++;
  34. }
  35. }
  36. }
  37. else {
  38. if (sword) {
  39. sword = false;
  40. wlength[wcount] = lcount;
  41. wcount++;
  42. }
  43. if (strict && sline[i] == '(')
  44. {
  45. scount++;
  46. }
  47. if (strict && sline[i] == ')')
  48. {
  49. scount--;
  50. }
  51. if (sline[i] == '.')
  52. {
  53. sentc++;
  54. }
  55. }
  56. }
  57. if (sword) {
  58. sword = false;
  59. wlength[wcount] = lcount;
  60. wcount++;
  61. }
  62. } while (sline != "END");
  63. try {
  64. if (wcount == 1)
  65. {
  66. throw "ERR: PROVIDE MATCHING PARENTHESES\n";
  67. }
  68. if (strict && scount != 0)
  69. throw "ERR: PROVIDE MATCHING PARENTHESES\n";
  70.  
  71. int k = 0;
  72. for (int j = 0; j < wcount - 1; j++){
  73. k += wlength[j];
  74. }
  75. double s = ((double)k) / (wcount -1);
  76. double sents = ((double)(wcount -1))/sentc;
  77. cout << round(sents) << ' ' << round(s) << endl;
  78. }
  79. catch (char *str){
  80. cout << str;
  81. }
  82.  
  83.  
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement