Results 1 to 10 of 10
Thread: cluster series
- 11-10-2012, 10:39 AM #1
Member
- Join Date
- Nov 2012
- Posts
- 9
- Rep Power
- 0
cluster series
I got a problem in hand where I can't find any solution yet.. I don't know how to explain this properly let me begin with some sample input outputs
Input: {1,1,2,3,3} => Output will be: 2
Input: {1,1,1,1,1} => Output will be: 1
Input: {1,2,1,1,1} => Output will be: 1
Input: {1,1,2,1,1,2,4,4} => Output will be: 3
So the thing is it will basically out put how many group of 2 or more same consecutive numbers in a series. I hope I'm not speaking gibberish
.
my code is incomplete/wrong.
Java Code:import javax.swing.JOptionPane; public class Cluster { public static void main(String[] args) { // TODO Auto-generated method stub String a= JOptionPane.showInputDialog("Enter Array size" ); int size= Integer.parseInt(a); int [] array = new int[size]; for(int i=0; i<size; i++){ a= JOptionPane.showInputDialog("Enter array elements" ); int n= Integer.parseInt(a); array[i]=n; System.out.print(" "+array[i]); } int flag=0; for (int j=0; j<size-1; j++){ if (array[j]!=array[j+1]){ flag=flag+1; if(array[j+1]!=array[j+2]){ } } } System.out.println(" Clusters "+flag); } }
- 11-10-2012, 12:52 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,380
- Blog Entries
- 7
- Rep Power
- 17
Re: cluster series
Explain in words how you would do it; no code please.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 11-10-2012, 01:12 PM #3
Member
- Join Date
- Nov 2012
- Posts
- 9
- Rep Power
- 0
- 11-10-2012, 01:41 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,380
- Blog Entries
- 7
- Rep Power
- 17
Re: cluster series
Just give it a try; make that wetware between your ears work.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 11-10-2012, 03:03 PM #5
Member
- Join Date
- Nov 2012
- Posts
- 9
- Rep Power
- 0
- 11-10-2012, 03:34 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,380
- Blog Entries
- 7
- Rep Power
- 17
Re: cluster series
As I wrote before: just give it a try; I know it won't be perfect (otherwise you wouldn't have started this thread), but you have to show some effort instead of begging for a spoonfeeding answer.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 11-10-2012, 03:52 PM #7
Member
- Join Date
- Nov 2012
- Posts
- 9
- Rep Power
- 0
- 11-10-2012, 04:58 PM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,380
- Blog Entries
- 7
- Rep Power
- 17
Re: cluster series
Ok, if you refuse to show your tries here ... never mind, goodbye and good luck with it.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 11-10-2012, 05:44 PM #9
Member
- Join Date
- Nov 2012
- Posts
- 9
- Rep Power
- 0
Re: cluster series
Ok I think there has been a miss-communication here. I though u were asking to try coding it again. I reread all the posts again and realized you were asking to explain the possible solution for it. Ok here it goes.
The way I'm trying to solve this problem is this
Lets go through this input and out put
Input: {1,1,2,3,3} => Output will be: 2
first I'll start a loop to see consecutive similar numbers in that array. and add a flag every time it finds two or more consecutive numbers. It will continue to go forward until it gets a different number. So here it will start the loop and when it will see two consecutive 1's then it will increase its counter/flag by 1. Then when it will find 2 which is a different number it will see if there is more 2's after that. Here it will see that there is 3 after 2 so no need to increase the flag. Next it will compare 3 with the next array element. which it will find that there is another 3. Now it will increase the counter / flag by one more. Next when it will reach the end of the array, it will just end the operation I guess.
I apologize for the miss-communication.
- 11-10-2012, 06:09 PM #10
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,380
- Blog Entries
- 7
- Rep Power
- 17
Re: cluster series
Apologies accepted; back to the problem: suppose you start at position i in your array; also suppose at position i starts a new sequence (this is always true if i == 0). Starting at that position, move to the right until you have reached either the end of the array or the element at the new position doesn't equal the element at position i. Call this position j. The value j-i is the length of the sequence; if it is larger than one, you found a real sequence. Next set i equal to j (one element beyond the sequence) and repeat the above steps until i reaches the end of the array. In code this scenario only requires one loop and a couple of if-statements. Your example:
1,1,2,3,3 (i= 0, j= 2 --> sequence length == 2)
1,1,2,3,3 (i= 2, j= 3 --> sequence length == 1)
1,1,2,3,3 (i= 3, j= 5 --> sequence length == 2)
1,1,2,3,3,(i= 5 at the end of the array, two 'real' sequences found)
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
Linux Cluster Management Console 1.0.1
By java software in forum Java SoftwareReplies: 0Last Post: 10-10-2011, 07:15 PM -
Linux Cluster Management Co...0.9.9
By java software in forum Java SoftwareReplies: 0Last Post: 10-05-2011, 06:01 PM -
Springs+Cluster+FileDownload
By j2ee_chap in forum Web FrameworksReplies: 3Last Post: 04-15-2011, 01:57 PM -
Help me with cluster !!
By ariuka in forum Advanced JavaReplies: 2Last Post: 09-16-2010, 12:40 PM -
Cluster using 2 machines
By Albert in forum Advanced JavaReplies: 2Last Post: 07-04-2007, 06:31 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks