fReaK
BAN USERAnon used SPLIT which means that this functionality is supported by the language he was using (ex- Java). Therefore, if SPLIT is available just use it to obtain the array with different words and print the array in reverse.
If,however, the function SPLIT is not defined for a language than this might be the optimum solution, but that isnt the case here since point 3 clearly uses SPLIT.
There exists only one copy of each method per class, be the method static or non-static. A thread needs to acquire the monitor of an appropriate object before entering a synchronized method which it releases when the thread returns from the method. In case of static synchronization the thread acquires the monitor of the class object, the locking is at class level so no other thread can execute it until the current thread releases the lock. In case of non-static synchronisation the thread acquires the monitor of that particular instance on which the call was made so other threads using different instances are not locked. They acquire monitors of there respective instances but continue to execute, as no two thread use the same instance. So what i feel is the non-static part will work faster i.e printB().
- fReaK November 21, 2013So here are two different working implementations of your code
#include<stdio.h>
#include<stdlib.h>
void mystrcpy( char **string2 ,char *string1 )
{
*string2 = malloc(20);
char *str = *string2;
while( *string1 != '\0')
{
*str++ = *string1++;
}
}
int main()
{
printf("****************program starts*************************");
char *str1 ="hello world";
char *str2 =NULL;
mystrcpy(&str2,str1);
printf("string1 = %s string2 =%s ",str1,str2);
return 0;
}
AND
#include<stdio.h>
#include<stdlib.h>
char* mystrcpy( char *string2 ,char *string1 )
{
string2 = malloc(20);
char *string = string2;
while( *string1 != '\0')
{
*string2++= *string1++;
}
return string;
}
int main()
{
printf("****************program starts*************************");
char *str1 ="hello world";
char *str2 =NULL;
str2 = mystrcpy( str2,str1);
printf("string1 = %s string2 =%s ",str1,str2);
return 0;
}
#include<stdio.h>
#include<stdlib.h>
int maxSubArraySum(int *);.
int maxSubArraySum(int *arr).
{
int *sum = (int *)calloc(sizeof(int), 8);.
int i, large = arr[0];.
sum[0] = arr[0];.
for (i=1;i<8;i++)
{
if (arr[i] >= 0).
{
if (sum[i-1] < 0).
sum[i] = arr[i];.
else
sum[i] = sum[i-1] + arr[i];.
}
if (arr[i] < 0 && (arr[i]+sum[i-1] >= 0)).
{
sum[i] = sum[i-1] + arr[i];.
}
else if(arr[i] < 0 && (arr[i]+sum[i-1] < 0 )).
{
sum[i] = arr[i];.
}
if (sum[i] > large).
large = sum[i];.
}
return large;
}
int main()
{
int arr[] = {-2,-3,4,-1,-2,1,5,-3};.
printf("Maximum sum - %d", maxSubArraySum(arr));.
getchar();
return;
}
- fReaK November 11, 2013String test = "aabbbcccdde";
String output = "";
int count = 1;
test = test + " ";
for (int i = 0; i < test.length() - 1; i++)
{
if (count == 1)
output = output + test.charAt(i);
if (test.charAt(i + 1) == test.charAt(i))
{
count++;
continue;
}
output = output + count;
count = 1;
}
System.out.println(output);
There exists only one copy of each method per class, be the method static or non-static. A thread needs to acquire the monitor of an appropriate object before entering a synchronized method which it releases when the thread returns from the method. In case of static synchronization the thread acquires the monitor of the class object, the locking is at class level so no other thread can execute it until the current thread releases the lock. In case of non-static synchronisation the thread acquires the monitor of that particular instance on which the call was made so other threads using different instances are not locked. They acquire monitors of there respective instances but continue to execute, as no two thread use the same instance.
- fReaK September 14, 2014