|
A random array of elements is given. Your program needs to find all the sections(sequences) in the array that are in ascending order, find the sum of those sequences, then find the largest sum and print the largest sum along with the sequence of numbers. For example if the array is like
4, 5, 6, 2, 1, 2, 3, 4, 12, 6, 4, 2, 1, 5, 8, 9
Then ascending sequences in the given array are
· 4,5,6 with sum 15
· 1,2,3,4,12 with sum 22
· 1,5,8,9 with sum 23
So your program should print the sequence 1 5 8 9 and the sum 23, as it’s the largest sum of ascending sequences.
|
|
|
|
|
Your homework is set to test what YOU know. If you can't do it, then talk to your teacher.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Sure, I'll help you. The key to solving this issue is to break it down into logical chunks from your requirements.
1. Find all ascending order sequences.
2. For each result from step 1, sum the values
3. Identify the largest out of step 2.
So, you see that you have three logical areas. You know that you have an array and that you start at element 0, so all you need to do to complete step 1 is to check to see if the next value is 1 greater than the current value or if you have reached the end of the list. Store your value in an appropriate data structure and move onto the next. Once you have completed this stage, proceed to break the other stages down into a logical set of steps and solve.
|
|
|
|
|
|
Pete O'Hanlon wrote: see if the next value is 1 greater than the current value It doesn't have to be 1 greater, just greater.
OP said that 1,2,3,4,12 was an example of a correct sequence.
(Ascending vs. sequential)
A positive attitude may not solve every problem, but it will annoy enough people to be worth the effort.
|
|
|
|
|
An excellent point. This is the problem with making assumptions.
|
|
|
|
|
And?
What have you tried?
Where are you stuck?
Why do you think we want to do your homework?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I'd like to see a solution using LINQ!
Regards,
Rob Philpott.
|
|
|
|
|
DataSet ds = new DataSet();
string f = dateTimePicker1.Text.ToString().Trim();
string t = dateTimePicker2.Text.ToString().Trim();
ds = bl.Totall(f,t);
dataGridView1.DataSource = ds.Tables[0];
but there is error :"Cannot find table 0".
plz help me.
|
|
|
|
|
Member 11479040 wrote: ds = bl.Totall(f,t); ..and what's that supposed to be / to do?
|
|
|
|
|
Your code looks like it's expecting a DataSet to be returned from Totall. Whatever goes on in this method should create and append the DataTable to a DataSet that is returned out. BTW, you can drop the initialisation of your DataSet and just call
DataSet ds = bl.Totall(f,t); Also, please use better variable names. I assume f means from and t means to.
|
|
|
|
|
ds.Tables[0]
is where the exception is happening - ds has a an array of tables called Tables .
The exception is being caused by the array being empty. Why it's empty I can't know, this line:
ds = bl.Totall(f,t);
is the closest anyone can get. Setting aside the mis-spelling of "Totall" which you might want to fix, the bl.Totall(...) method isn't returning an array with anything in it - so that method is your problem. As you haven't provided the code for that method, we can't tell why it's returning an empty array. If you want further help, you'll need to post the code for that method and anything else associated with it that is relevant.
|
|
|
|
|
A was looking at now of the projects which describing how to simulate mouse movement and clicking on a certain coordinates.
I wrote this code based on what I learned from that project, it's actually the same..
but it's not working..
if this code is not correct
is there any way of doing that ? and how to implement that..
this the code
[DllImport("User32.dll")]
public static extern void mouse_event(MouseEventType dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
[DllImport("User32.dll")]
public static extern int SetCursorPos(int x, int y);
public enum MouseEventType : int
{
LeftDown = 0x02 , LeftUp= 0x04, RightDown= 0x08, RightUp= 0x10
}
and here is event handler, so when I click the button the mouse supposed to move to the coordinates..
private void button1_Click(object sender, EventArgs e)
{
SetCursorPos(300, 200);
mouse_event(MouseEventType.LeftDown, Cursor.Position.X, Cursor.Position.Y, 20, 20);
mouse_event(MouseEventType.LeftUp, Cursor.Position.X, Cursor.Position.Y, 20, 20);
}
any help in this,,
thanks
|
|
|
|
|
"but it's not working.."
That's not helpful.
What is it doing that you didn't expect, or not doing that you did?
Remember that we can't see your screen, access your HDD, or read your mind - we only get what you tell us to work with!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I only need to move the mouse to any coordinate after clicking on a button, only that is it!
I have a form application contains only a button, when I click the button (as you can see from the handler) I just need the mouse to be moved to any coordinate..
I know It may not difficult, but I couldn't do it till now..
I'm using VS 2012 ultimate..
thanks
|
|
|
|
|
And? What is happening when you run your code?
I really can't see your screen!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
if you mean the code which I written, nothing happens, it's not working at all. when I click the button nothing happens!!
if you mean what I need to get, it's only moving the mouse without touching any thing!!
|
|
|
|
|
|
Well, you could start by using .NET cursor movement:
Point current = Cursor.Position;
Cursor.Position = new Point(current.X + 50, current.Y + 10);
And then this works for me:
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void mouse_event(uint dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
private const uint MOUSEEVENTF_LEFTDOWN = 0x02;
private const uint MOUSEEVENTF_LEFTUP = 0x04;
private const uint MOUSEEVENTF_RIGHTDOWN = 0x08;
private const uint MOUSEEVENTF_RIGHTUP = 0x10;
private void butClickMe_Click(object sender, EventArgs e)
{
Point current = Cursor.Position;
Cursor.Position = new Point(current.X + 50, current.Y + 10);
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, Cursor.Position.X, Cursor.Position.Y, 0, 0);
} By putting a second button on the form, slightly right and down from the first, it gets clicked every time...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Thanks OriginalGriff
the code is working ,,
but I have one more question
if I need for example to first LEFTDOWN and then move the cursor somewhere and then LEFTUP.
can we do that ?
As I know, MOVE mouse event is like
private const uint MOUSEEVENTF_MOVE = 0x0001
it's not working, and when I comment it the mouse events work fine..
how can we implement this ?
thanks,
|
|
|
|
|
The chances are that you can't do it quite like that: the way windows handles messages is probably why - they get queued, not executed immediately, so it's very unlikely that
Left down
Move mouse
left up will be executed in that sequence.
It's possible (I haven't tried) that this would work:
mouse_event(MOUSEEVENTF_LEFTDOWN, Cursor.Position.X, Cursor.Position.Y, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, Cursor.Position.X + 100, Cursor.Position.Y + 100, 0, 0); It probably should.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I tried this one many times before
mouse_event(MOUSEEVENTF_LEFTUP, Cursor.Position.X + 100, Cursor.Position.Y + 100, 0, 0);
But the cursor not moves andy stay in the same position
and when I use this one
mouse_event(MOUSEEVENTF_MOVE, Cursor.Position.X, Cursor.Position.Y ,0, 0);
it also not moves the mouse
I tried to add some numbers to the coordinates but it's not working also,,
|
|
|
|
|
No, mouse_event won't move the mouse - it just signals that a mouse event occurred at the location, even if the mouse wasn't (and isn't) anywhere near it.
If you want the mouse to move, the operation to happen, and the mouse to move again, then you are going to have to use timers to move it, then issue a command, then wait for the next timer tick before doing the next event.
Just what are you trying to write here - I'm interested?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
So why don't you call SetCursorPos as that function does exctly what you want. It sets the mouse cursor to the specified location.
What you are doing is creating a mouse event. If nothing at that position you specified is able to respond to that event, then you'll see absolutely nothing.
Oh, but wait you would see something if you were looking at it. Everytime you klick somewhere on the screen or raise an event to that effect, the idle timer is reset to 0.
Cheers!
P.S. I just checked and it seems you can also raise mouse moved events read all about it here: mouse_event function[^], but you should know that the SendInput[^]function should be called instead.
"I had the right to remain silent, but I didn't have the ability!"
Ron White, Comedian
|
|
|
|
|
I want convert code C# 2008 to code C# 2005, I did not understand the command C# 2008 to switch to C# 2005, see below is the error code can solve the error command do ? run the code in C# 2008 very good
[code]
private void textBox1_TextChanged(object sender, EventArgs e)
{
string str = textBox1.Text.Trim();
if (!string.IsNullOrEmpty(str))
{
// Error in here
Expression<func<customdata, bool="">> expr = n => GetCondition(n, str);
this.gridControl1.DataSource = this.lstCustomData.Where<customdata>(expr.Compile()).ToList();
}
else
this.gridControl1.DataSource = this.lstCustomData;
this.gridControl1.RefreshDataSource();
}
public class CustomData
{
// Error in here
public int col1 { get; set; }
public string col2 { get; set; }
public string col3 { get; set; }
public int col4 { get; set; }
}
[/code]
|
|
|
|
|