fork download
  1. #include<stdio.h>
  2. #include<cstring>
  3. #include<iostream>
  4. #include<limits.h>
  5. using namespace std;
  6.  
  7. int palindromicsumstring(char *s, int n){
  8.  
  9. int sum[n][n];
  10. int ans = INT_MIN;
  11. for(int i =0 ;i<n;i++){
  12. sum[i][i]=s[i]-'0';
  13. }
  14. // This is length of substring, that can be your possible answer
  15.  
  16. for(int l = 2;l<=n;l++){
  17. // This is the starting index of your substring
  18. for(int i = 0;i<=n-l;i++){
  19. //This is end point of the substring
  20. int j = i+l-1;
  21. //This is middle point of substring
  22. int k = i+(l/2)-1;
  23.  
  24.  
  25. // Find total sum of the substring from
  26. //previous memorized states : Dynamic Programming
  27. sum[i][j] = sum[i][k]+sum[k+1][j];
  28.  
  29. // l is even , then check for the possible answer
  30. if(l%2==0){
  31. if(sum[i][k] == sum[k+1][j]){
  32.  
  33. ans = max(ans , l );
  34. }
  35. }
  36.  
  37. }
  38.  
  39. }
  40.  
  41. return ans;
  42. }
  43.  
  44.  
  45. int main(){
  46. //Number
  47. int sum;
  48. char s[] = "1538023";
  49. //Function Call
  50. palindromicsumstring(s,strlen(s));
  51.  
  52. cout<‹ans<<endl;
  53.  
  54. return 0;
  55. }
Compilation error #stdin compilation error #stdout 0s 15240KB
stdin
Standard input is empty
compilation info
prog.cpp:52:6: error: stray ‘\342’ in program
 cout<‹ans<<endl;
      ^
prog.cpp:52:7: error: stray ‘\200’ in program
 cout<‹ans<<endl;
       ^
prog.cpp:52:8: error: stray ‘\271’ in program
 cout<‹ans<<endl;
        ^
prog.cpp: In function ‘int main()’:
prog.cpp:52:9: error: ‘ans’ was not declared in this scope
 cout<‹ans<<endl;
         ^~~
stdout
Standard output is empty