fork download
  1. //CodeChef submission 6245801 (C++ 4.9.2) plaintext list. Status: WA, problem CHEFCH, contest FEB15. By gammer (gammer), 2015-02-13 14:23:03.
  2. #include <iostream>
  3. #include<string>
  4. using namespace std;
  5.  
  6. long chain(){
  7. string s; long i=0,y,count=0,count2=0;
  8. cin>>s;
  9. long n=s.size();
  10. if(n<=1)
  11. return 0;
  12. while(i<n){
  13. if( s[i]==s[++i]){
  14. y=--i;
  15. break;
  16.  
  17. }
  18. if(i==n-1){
  19. return 0;}
  20. }
  21.  
  22. while(y<(n-1)){
  23. if(s[i]==s[++y])
  24. count++;
  25. if(y==(n-1)){break;}
  26. if(s[i]!=s[++y]){
  27. count++;
  28. }
  29. }
  30. y=i;
  31. while(y>0){
  32. if(s[i]==s[--y])
  33. count++;
  34. if(y==0){
  35. break;
  36. }
  37. if(s[i]!=s[--y])
  38. count++;
  39. }
  40.  
  41.  
  42. i++;
  43. y=i;
  44. while(y<(n-1)){
  45. if(s[i]!=s[++y])
  46. count2++;
  47. if(y==(n-1)){break;}
  48. if(s[i]==s[++y]){
  49. count2++;
  50. }
  51. }
  52. y=i;
  53. while(y>0){
  54. if(s[i]!=s[--y])
  55. count2++;
  56. if(y==0){
  57. break;
  58. }
  59. if(s[i]==s[--y])
  60. count2++;
  61. }
  62.  
  63. cout<<count<<" "<<count2<<endl;
  64. if(count<=count2)
  65. return count;
  66. else
  67. return count2;
  68. }
  69.  
  70.  
  71.  
  72.  
  73. int main() { long a; int t;
  74. cin>>t;
  75. while(t>0){a=chain();
  76. cout<<a<<endl;
  77. t--;
  78. }
  79.  
  80.  
  81. return 0;
  82. }
Success #stdin #stdout 0s 2868KB
stdin
2
--------------------------------------------+++++++++++++----------------------------------------------------------------+---++++++-+-+-----++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------+++++-+-+---+++-----++++++-------+++-----++-+-++-++++++++++------------------------------++-++-+-+-+-+-+-+-+-+-+-+-+-+-+-++++++++-----------+-++-+-+++++++++++++++++----------------+-+-+-+-+-+-+---++++++++++--------------------------------------
++-+
stdout
245  244
244
3  2
2