Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include<cmath>
- #include<exception>
- using namespace std;
- int main() {
- char line[1000];
- string sline;
- int wlength[100];
- int wcount = 0, lcount, i, scount, sentc = 0;//broi izr
- bool sword = false, start = true, strict = false;
- do {
- cin.getline(line, 1000, '\n');
- sline = line;
- if (start && sline == "strict") {
- scount = 0; strict = true;
- continue;
- }
- for (i = 0; i < sline.length(); i++){
- if ((sline[i] >= 'a' && sline[i] <= 'z') || (sline[i] >= 'A' && sline[i] <= 'Z'))
- {
- if (i == 0 || !sword) {
- sword = true;
- lcount = 1;
- }
- else {
- if (sword){
- lcount++;
- }
- }
- }
- else {
- if (sword) {
- sword = false;
- wlength[wcount] = lcount;
- wcount++;
- }
- if (strict && sline[i] == '(')
- {
- scount++;
- }
- if (strict && sline[i] == ')')
- {
- scount--;
- }
- if (sline[i] == '.')
- {
- sentc++;
- }
- }
- }
- if (sword) {
- sword = false;
- wlength[wcount] = lcount;
- wcount++;
- }
- } while (sline != "END");
- try {
- if (wcount == 1)
- {
- throw "ERR: PROVIDE MATCHING PARENTHESES\n";
- }
- if (strict && scount != 0)
- throw "ERR: PROVIDE MATCHING PARENTHESES\n";
- int k = 0;
- for (int j = 0; j < wcount - 1; j++){
- k += wlength[j];
- }
- double s = ((double)k) / (wcount -1);
- double sents = ((double)(wcount -1))/sentc;
- cout << round(sents) << ' ' << round(s) << endl;
- }
- catch (char *str){
- cout << str;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement