dev
BAN USER#include<stdio.h>
int find_sum(char*s);
main()
{
char s[100];
scanf("%s",s);
printf("\nSum = %d",find_sum(s));
}
int find_sum(char* s)
{
int sum=0;
int temp_sum=0;
while((*s)!='\0')
{
if((*s)>='0'&&(*s)<='9')
{
temp_sum=10*temp_sum+(*s)-'0';
}
else
{
sum=sum+temp_sum;
temp_sum=0;
}
++s;
}
sum=sum+temp_sum;
return sum;
}
- dev August 30, 2012as it is a binary tree not binary search tree,
we have to do more work minimum time complexity will be O(n)
simply do inorder traversal of this tree,note the position of y wrt to x and z,it must be central if it is not then say false,else if it is central than one more test has to be performed to confirm , then perform post order traversal note the position of y with respect to x and z it must be after the x and z.
pretty simple use an array of 26 length initialize it to zero u can use 257 length also but it depends the type of character set you are using read string a "+1" for every character similarly for every character in b.Now start reading string c do "-1" for every character on array if at any time the value in array goes below 0 while doing -1 then it is not interleaved,after doing this do check whether whole array is agail zero or not if not again not interleaved.
actualyy this problem is that finding whether c is a permutation of string "a+b".
- dev August 30, 2012