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.  
  38.  
  39. //---------> Am numarat cuvintele <-----------------------
  40. int findMatch = 0,cntr = 0, pos2 = 0;;
  41. for (int i = 1; i < length + 1; ++i) {
  42. int flag = 1;
  43. for (int j = i; j < length + 1 && flag == 1; ++j) {
  44.  
  45. if (b[i] == b[j] && (b[i] >= 'A' && b[i] <= 'Z')) {
  46. ++cntr;
  47. //cout << cntr << " " << j <<"\n";
  48. //i = cntr + 1;
  49. //cout << i <<"<->" << j <<"<->"<< cntr <<"\n";
  50. } else if (b[i] != b[j]) { // && cntr > findMatch
  51. flag = 0;
  52. if (cntr > findMatch) {
  53. findMatch = cntr; // 3,
  54. pos2 = j ;
  55. }
  56. //findMatch = cntr; // 3,
  57. // pos2 = j ;
  58. //cout << i << " " << j << " " << cntr<< " Nu-i identic" << "\n";
  59. i = j - 1;
  60. cntr = 0;
  61. }
  62. if ((cntr > findMatch && j == length) || j == length ) {
  63.  
  64. if (cntr > findMatch) {
  65. findMatch = cntr;
  66. pos2 = j + 1;// 3,
  67. }
  68. i = j;
  69. // cout << "DAAAA\n";
  70. }
  71. }
  72. }
  73.  
  74. int isPrime = 1;
  75. for (int div = 2; div < findMatch; ++div) {
  76. if (findMatch % div == 0) {
  77. isPrime = 0;
  78. }
  79. }
  80. if (findMatch == 1) {
  81. isPrime = 0;
  82. }
  83. cout << findMatch << "<->" << pos2 << " |" << length << "<- length|\n";
  84. if (isPrime == 1 && capitalLetter == length || (isPrime == 1 && capitalLetter != length )) {
  85. cout << pos2 - findMatch <<" <pos> " << pos2 - 1;
  86. } else {
  87. cout << words << "<- words";
  88. }
  89. return 0;
  90. }
  91.  
  92. // else if (isPrime == 1 && pos2 == length && pos2 == findMatch){
  93. // cout << pos2 - findMatch + 1 <<"<Cazul 2> " << pos2 - 1;
  94. // }
Success #stdin #stdout 0s 5312KB
stdin
AzsXDC FFF GDGvbA

SSSSAAADDDDD
AASXDCFVFHNGHT
SXDCFVFHNGHTTT
AXDCAAAXCVBNSSSSSAAAAAAA

SXDCFVFHNGHTTT






AA

AASXDCFVFHNGHT

VV



AA

ARGSFGHADFHSRTHYHSFGNH SSDGDSFGSFGFHADRG

ASD DSA AAA EEE AAAAA ERDFER

AAA BBBBB WWWWWWW
A

BBBALIZILABBB





BBBALIZILABBB

ASZXDCFFFFFSXCDVGTGNGTHY
stdout
17 11<----
3<->11 |17<- length|
8 <pos> 10