Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <iomanip>
  4. #include <math.h>
  5. #include <string>
  6. #include <vector>
  7. #include <queue>
  8. #include <stack>
  9. #include <map>
  10. #include <set>
  11.  
  12. using namespace std;
  13.  
  14. struct help
  15. {
  16.     int count, max_len;
  17. };
  18.  
  19. int main()
  20. {
  21.     string s;
  22.    
  23.     vector<help> count;
  24.     help h;
  25.     h.count = 0;
  26.     h.max_len = 0;
  27.     count.push_back(h);
  28.  
  29.     int max_len = 0, max_count_word = 0;
  30.  
  31.     while (cin >> s)
  32.     {
  33.         int l = 0, r = s.size() - 1, n = s.size();
  34.         if (s[r] == '.' || s[r] == '?' || s[r] == '!' || s[r] == ',')
  35.         {
  36.             r--;
  37.             n--;
  38.         }
  39.  
  40.         bool b = true;
  41.         while (l < r)
  42.         {
  43.             if (s[l] != s[r])
  44.             {
  45.                 b = false;
  46.                 break;
  47.             }
  48.             l++;
  49.             r--;
  50.         }
  51.  
  52.         int last = count.size() - 1;  
  53.         if (b)
  54.         {
  55.             count[last].count++;
  56.             count[last].max_len = max(count[last].max_len, n);
  57.         }
  58.  
  59.         n = s.size() - 1;
  60.         if (s[n] == '.' || s[n] == '?' || s[n] == '!')
  61.         {
  62.             max_count_word = max(max_count_word, count[last].count);
  63.             count.push_back(h);
  64.         }
  65.     }
  66.  
  67.     vector<int> v1;
  68.     for (int i = 0; i < count.size(); i++)
  69.         if (max_count_word == count[i].count)
  70.             v1.push_back(i);
  71.  
  72.     for (int i = 0; i < v1.size(); i++)
  73.         max_len = max(max_len, count[v1[i]].max_len);
  74.    
  75.     vector<int> v2;
  76.     for (int i = 0; i < v1.size(); i++)
  77.         if (count[v1[i]].max_len == max_len)
  78.             v2.push_back(v1[i]);
  79.  
  80.     int ans_i = v2[0];
  81.     cout << ans_i + 1 << endl;
  82.     cout << count[ans_i].count << ' ' << count[ans_i].max_len << endl;
  83.  
  84.     return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement