fork download
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. const int MAX_LENGTH = 1000;
  6.  
  7. int isWord (char x) {
  8. if ((x >= 'A' && x <= 'Z') || (x >= 'a' && x <= 'z')) {
  9. return 1;
  10. }
  11. return 0;
  12. }
  13.  
  14.  
  15. int main() {
  16. char a[MAX_LENGTH], b[MAX_LENGTH + 1];
  17. cin.getline(a, MAX_LENGTH);
  18. int length = strlen(a);
  19. // cout << length <<"<<--\n";
  20. int words = 0, letter = 0, capitalLetter = 0;
  21. for (int i = 0; i < length; ++i) {
  22. if (a[i] >= 'A' && a[i] <= 'Z') {
  23. ++capitalLetter;
  24. }
  25. if (isWord(a[i]) == 1) {
  26. letter = 1;
  27. } else if (letter == 1) {
  28. ++words;
  29. letter = 0;
  30. }
  31. b[i + 1] = a[i];
  32. }
  33. if(letter == 1) {
  34. ++words;
  35. }
  36. cout << length << " " << capitalLetter <<"<----\n";
  37. int prime = 1;
  38. for (int div = 2; div < capitalLetter; ++div) {
  39. if (capitalLetter % div == 0) {
  40. prime = 0;
  41. }
  42. }
  43. if (capitalLetter == 1) {
  44. prime = 0;
  45. }
  46.  
  47.  
  48.  
  49. //---------> Am numarat cuvintele <-----------------------
  50. int findMatch = 0,cntr = 0, pos2 = 0;;
  51. for (int i = 1; i < length + 1; ++i) {
  52. int flag = 1;
  53. for (int j = i; j < length + 1 && flag == 1; ++j) {
  54.  
  55. if (b[i] == b[j] && (b[i] >= 'A' && b[i] <= 'Z')) {
  56. ++cntr;
  57. //cout << cntr << " " << j <<"\n";
  58. //i = cntr + 1;
  59. //cout << i <<"<->" << j <<"<->"<< cntr <<"\n";
  60. } else if (b[i] != b[j]) { // && cntr > findMatch
  61. flag = 0;
  62. if (cntr > findMatch) {
  63. findMatch = cntr; // 3,
  64. pos2 = j ;
  65. }
  66. //findMatch = cntr; // 3,
  67. // pos2 = j ;
  68. //cout << i << " " << j << " " << cntr<< " Nu-i identic" << "\n";
  69. i = j - 1;
  70. cntr = 0;
  71. }
  72. if ((cntr > findMatch && j == length) || j == length ) {
  73.  
  74. if (cntr > findMatch) {
  75. findMatch = cntr;
  76. pos2 = j;// 3,
  77. }
  78. i = j;
  79. // cout << "DAAAA\n";
  80. }
  81. }
  82. }
  83. cout << findMatch << "<->" << pos2 << "\n";
  84. int isPrime = 1;
  85. for (int div = 2; div < findMatch; ++div) {
  86. if (findMatch % div == 0) {
  87. isPrime = 0;
  88. }
  89. }
  90. if (findMatch == 1) {
  91. isPrime = 0;
  92. }
  93.  
  94. if (isPrime == 1 && capitalLetter == length) { // capitalLetter == length
  95. cout << pos2 - findMatch <<" " << pos2 - 1;
  96. } else {
  97. cout << words;
  98. }
  99. return 0;
  100. }
Success #stdin #stdout 0.01s 5288KB
stdin
ARGSFGHADFHSRTHYHSFGNH SSDGDSFGSFGFHADRG

ASD DSA AAA EEE AAAAA ERDFER

AAA BBBBB WWWWWWW
BBBALIZILABBB





BBBALIZILABBB

ASZXDCFFFFFSXCDVGTGNGTHY
stdout
40 39<----
2<->26
2