fork(1) 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 >> a;
  18. int length = strlen(a);
  19.  
  20. int words = 0, letter = 0;
  21. for (int i = 0; i < length; ++i) {
  22. if (isWord(a[i]) == 1) {
  23. letter = 1;
  24. } else if (letter == 1) {
  25. ++words;
  26. letter = 0;
  27. }
  28. b[i + 1] = a[i];
  29. }
  30. if(letter == 1) {
  31. ++words;
  32. }
  33.  
  34. int finMatch = 0,cntr = 0, pos2 = 0;;
  35. for (int i = 1; i < length + 1; ++i) {
  36. int flag = 1;
  37. for (int j = i; j < length + 1 && flag == 1; ++j) {
  38.  
  39. if (b[i] == b[j] ) {
  40. ++cntr;
  41. //cout << cntr << " " << j <<"\n";
  42. //i = cntr + 1;
  43. cout << i <<"<->" << j <<"<->"<< cntr <<"\n";
  44. } else if (b[i] != b[j]) { // && cntr > finMatch
  45. flag = 0;
  46. if (cntr > finMatch) {
  47. finMatch = cntr; // 3,
  48. }
  49. //finMatch = cntr; // 3,
  50. pos2 = j ;
  51. cout << i << " " << j << " " << cntr<< " Nu-i identic" << "\n";
  52. i = j - 1;
  53. cntr = 0;
  54. }
  55. if (cntr > finMatch && j == length || j == length ) {
  56.  
  57. if (cntr > finMatch) {
  58. finMatch = cntr; // 3,
  59. }
  60. i = j;
  61. cout << "DAAAA\n";
  62. }
  63. }
  64. }
  65. cout << finMatch << " " << pos2;
  66.  
  67.  
  68. for ( int i = pos2 ; i < length + 1; ++i) {
  69. // cout << b[i] <<" ";
  70. }
  71. //cout << pos2 << " " << pos2 + finMatch - 1;
  72.  
  73. /*
  74. int matches = 0, counterMatches = 1;
  75. for (int i = 2; i < length + 1; ++i) {
  76. if (b[1] == b[i] && b[1] == b[length - (i - 1) + 1]) {
  77. ++counterMatches;
  78. //cout << counterMatches <<" " <<b[1] << " "<< b[length - (i - 1) + 1] <<" ";
  79. // cout << i <<" " << length - i + 1 <<"\n";
  80. }
  81. if (b[1] != b[i] && counterMatches >= matches) {
  82. matches = counterMatches;
  83. counterMatches = 1;
  84. }
  85. }
  86. //cout << matches;
  87. //cout << words <<"\n";
  88. int posA = 1, posB = 1;
  89. int counter = 0;
  90. for (int i = 1; i < length / 2 + 1; ++i) { //cout << i << " " << length - i + 1 <<"\n";
  91.  
  92. if (b[i] == b[length - i + 1]) {
  93. ++counter;
  94. posB = i;
  95. } else if (b[i] != b[length - i + 1]) {
  96. posA = i - counter;
  97. counter = 0;
  98. }
  99. }
  100.  
  101.  
  102. cout << b[i]<< " " << b[length - i + 1]<<" ";
  103. cout << i << " " << length - i + 1 <<"\n";
  104.  
  105.  
  106. for ( int i = 0; i < length; ++i) {
  107. if ((a[i] > 'A' || a[i] < 'Z') && (a[i] == a[length - i])) { //AAAa123BCDAAA!@#zxswAA
  108.  
  109. }
  110. }
  111.  
  112. */
  113. // cout << length /2;
  114. //cout << a << "\n"<< length;
  115. return 0;
  116. }
Success #stdin #stdout 0.01s 5308KB
stdin
BBBBBBBBBBBBALIZILABBBbbbbbb
stdout
1<->1<->1
1<->2<->2
1<->3<->3
1<->4<->4
1<->5<->5
1<->6<->6
1<->7<->7
1<->8<->8
1<->9<->9
1<->10<->10
1<->11<->11
1<->12<->12
1 13 12 Nu-i identic
13<->13<->1
13 14 1 Nu-i identic
14<->14<->1
14 15 1 Nu-i identic
15<->15<->1
15 16 1 Nu-i identic
16<->16<->1
16 17 1 Nu-i identic
17<->17<->1
17 18 1 Nu-i identic
18<->18<->1
18 19 1 Nu-i identic
19<->19<->1
19 20 1 Nu-i identic
20<->20<->1
20<->21<->2
20<->22<->3
20 23 3 Nu-i identic
23<->23<->1
23<->24<->2
23<->25<->3
23<->26<->4
23<->27<->5
23<->28<->6
DAAAA
12 23