Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualCornstalks

Posted 10 December 2012 - 11:07 PM

Please use [ code ][ /code ] (without spaces) tags (to get pretty formatted code)! I'll recreate it here in the meantime:

int getEqualSumSubstring(string s) {
    int i=0,j=i,foundLength=0;
    for(i=0;i<s.length();i++)
    {
        for(j=i;j<s.length();j++)
        {
            int temp = j-i+1;

            if(temp%2==0)
            {
                int leftSum=0,rightSum=0;
                string tempString=s.substr(i,temp);
                // printf("%d ",tempString.length());
                for(int k=0;k<temp/2;k++)
                {
                    leftSum=leftSum+tempString[k]-48;
                    rightSum=rightSum+tempString[k+(temp/2)]-48;
                }
                if((leftSum==rightSum)&&(leftSum!=0))
                    if(tempString.length()>foundLength)
                    foundLength=tempString.length(); 
            }
        }
    }
    return(foundLength);
}

I'd help analyze it but I've got to study for some finals Posted Image

#1Cornstalks

Posted 10 December 2012 - 11:06 PM

Please use [ code ][ /code ] (without spaces) tags (to get pretty formatted code)! I'll recreate it here in the meantime:

nt getEqualSumSubstring(string s) {
    int i=0,j=i,foundLength=0;
    for(i=0;i<s.length();i++)
    {
	    for(j=i;j<s.length();j++)
	    {
		    int temp = j-i+1;
		    if(temp%2==0)
		    {
			    int leftSum=0,rightSum=0;
			    string tempString=s.substr(i,temp);
			    // printf("%d ",tempString.length());
			    for(int k=0;k<temp/2;k++)
			    {
				    leftSum=leftSum+tempString[k]-48;
				    rightSum=rightSum+tempString[k+(temp/2)]-48;
			    }
			    if((leftSum==rightSum)&&(leftSum!=0))
				    if(tempString.length()>foundLength)
				    foundLength=tempString.length();
		    }
	    }
    }
    return(foundLength);
}

I'd help analyze it but I've got to study for some finals Posted Image

PARTNERS